Skip to content

Instantly share code, notes, and snippets.

@prenagha
Last active May 27, 2018 00:39
Show Gist options
  • Save prenagha/8402640 to your computer and use it in GitHub Desktop.
Save prenagha/8402640 to your computer and use it in GitHub Desktop.
run terminal command and return results directly back to launchbar
--
-- run terminal command and return results directly back to launchbar
-- runs command using applescript which means under /bin/sh
-- switches to user home dir before running script
--
-- take string from LaunchBar and run as command
on handle_string(theText)
try
set cmd to "cd ~ && " & theText
set output to (do shell script cmd)
tell application "LaunchBar"
set selection as list to output
activate
end tell
on error e
tell application "LaunchBar" to display in large type "Error: " & e
end try
end handle_string
-- run as file as a script
on open (theFile)
try
set pFile to (POSIX path of theFile) as text
set cmd to "cd ~ && " & pFile
set output to (do shell script cmd)
tell application "LaunchBar"
set selection as list to output
activate
end tell
on error e
tell application "LaunchBar" to display in large type "Error: " & e
end try
end open
-- otherwise run whatever is in clipboard
-- enable this if you like, just be careful
--set clip to the clipboard
--handle_string(clip)
@symmetriq
Copy link

Thanks! I adapted the open version to run a specific shell script and do something with it.

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