Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save flyfloor/afaa225442522ba95f8f to your computer and use it in GitHub Desktop.
Save flyfloor/afaa225442522ba95f8f to your computer and use it in GitHub Desktop.
Fix bug that Alfred can't run command with iTerm 2.1.1
-- This is v0.3 of the custom script for AlfredApp for iTerm 2.1.1
-- 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 alfred_script(q)
if is_running("iTerm") then
run script "
on run {q}
tell application \":Applications:iTerm.app\"
activate
tell the first terminal
set mysession to (launch session \"Default Session\")
tell mysession 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
tell the first terminal
tell the last session to write text q
end tell
end tell
end run
" with parameters {q}
end if
end alfred_script
@flyfloor
Copy link
Author

flyfloor commented Sep 9, 2015

Usage

Alfred --> Features --> Terminal/Shell --> Application --> Custom, copy content above to that field

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment