Jump to content

Recommended Posts

Hey everybody!

 

I am working on this workflow where I have a file filter with the most important text files (for me, at least) to open with vim in iTerm. 

 

OSTlcQf.png

 

Currently I have it configured so that I can choose to just run vim and get a new document or I can choose to run "v $SOMEFILE" in Alfred to make it open that way.

 

w0MRmf1.png

 

It's super cool, I've used https://github.com/stuartcryan/custom-iterm-applescripts-for-alfred/ and Macvimtoolbox as inspiration for this. There is one bug, however. 

 

When the active iTerm window is not just showing a prompt but engaged, then the script doesn't open a new windows but just pastes the "nvim /path/to/file" into the window. I'd like to configure the Apple-script to just open a new window in that case. How do I do that? 

 

 

The code I'm using is here, btw: 

 

on alfred_script(q) 
my runIniTerm( "nvim " & q & "" )
end alfred_script

-- This is v0.5 of the custom script for AlfredApp for iTerm 2.9+
-- Please see https://github.com/stuartcryan/custom-iterm-applescripts-for-alfred/
-- for the latest changes.

on is_running(app_name)
    tell application "System Events" to (name of processes) contains app_name
end is_running

-- Please note, if you store the iTerm binary in any other location than the Applications Folder
-- please ensure you update the two locations below (in the format of : rather than / for folder dividers)
-- this gets around issues with AppleScript not handling things well if you have two iTerm binaries on your system... which can happen :D

on runIniTerm(q)
    if is_running("iTerm2") or is_running("iTerm") then
        run script "
            on run {q}
                tell application \":Applications:iTerm.app\"
                    activate
                    try
                        select first window
                        set onlywindow to true
                    on error
                        create window with default profile
                        select first window
                        set onlywindow to true
                    end try
                    tell the first window
                        if onlywindow is false then
                            create tab with default profile
                        end if
                        tell current session to write text q
                    end tell
                end tell
            end run
        " with parameters {q}
    else
        run script "
            on run {q}
                tell application \":Applications:iTerm.app\"
                    activate
                    try
                        select first window
                    on error
                        create window with default profile
                        select first window
                    end try
                    tell the first window
                        tell current session to write text q
                    end tell
                end tell
            end run
        " with parameters {q}
    end if
end runIniTerm

 

The workflow can be found here:

https://transfer.sh/Ul5L3/Open-files-with-Vim.alfredworkflow

Edited by Virgilius Haufniensis

Share this post


Link to post

Please post the actual workflow, not pictures and extracts of it. Upload it somewhere and post a link. 

 

It's unreasonable to expect us to first rebuild your workflow in order to help you.

 

Share this post


Link to post

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...