Skip to content

Instantly share code, notes, and snippets.

@n8henrie
Last active August 15, 2022 03:57
Show Gist options
  • Save n8henrie/5278074 to your computer and use it in GitHub Desktop.
Save n8henrie/5278074 to your computer and use it in GitHub Desktop.
Template for writing Quicksilver (>= v1.0) actions in AppleScript
(*
Template for writing Quicksilver (>= v1.0) actions in AppleScript
See post at: http://n8henrie.com/2013/03/template-for-writing-quicksilver-actions-in-applescript/
Reference: http://qsapp.com/wiki/AppleScript_Types
See another example at:
http://blog.qsapp.com/post/46268365849/quicksilver-comes-of-age
## Update 20160318:
- Refactored into functions and added `on run` section for easier testing
*)
property testFirstPaneStuff : "This is from the first pane."
property testThirdPaneStuff : "This is from the third pane."
on process_text(firstPaneStuff, thirdPaneStuff)
display notification firstPaneStuff
display notification thirdPaneStuff
return firstPaneStuff & " " & thirdPaneStuff
end process_text
using terms from application "Quicksilver"
-- This sets object types for which the action will appear.
-- If you select this object type (in 1st pane),
-- your action will appear as an option (2nd pane)
on get direct types
return {"NSStringPboardType"}
end get direct types
-- Optional, use if you want to use a third pane.
-- This sets bject types you want to appear in the third pane, if any,
-- after your action is selected in the 2nd
on get indirect types
return {"NSFilenamesPboardType"}
end get indirect types
(*
Valid types:
"NSFilenamesPboardType" Files and folders
"NSStringPboardType" Text or a string
"Apple URL pasteboard type" URLs
"QSFormulaType" Formulas as used by the Calculator Plugin
"qs.process" Running applications or processes
"qs.command" Quicksilver command
"QSRemoteHostsType" Remote hosts (from the Remote Hosts Plugin)
"com.apple.itunes.track" iTunes tracks (indexed by the iTunes Plugin)
*)
-- thirdPaneStuff is optional
on process text firstPaneStuff with thirdPaneStuff
try
set returned to process_text(firstPaneStuff, thirdPaneStuff)
-- If you want to send anything back to Quicksilver, optional
tell application "Quicksilver" to set selection to returned
on error a number b
activate
display dialog a with title "error with your QS action script"
end try
end process text
-- Return 2 if using 1st and 3rd pane
-- Return 1 if only using 1st pane (no 2nd argument)
-- Must restart QS to reflect changes here.
on get argument count
return 2
end get argument count
end using terms from
on run
set returned to process_text(testFirstPaneStuff, testThirdPaneStuff)
-- If you want to send anything back to Quicksilver, optional
tell application "Quicksilver" to set selection to returned
end run
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment