Alex Balgavy

Just some stuff about me.

Here's my dotfiles repository.

Check out my blog.

My keys: PGP, SSH

My crypto wallets (BTC, XMR)

AppleScript cheat sheet

Custom functions (have to

to customFunctionName(param1, param2)
(* function contents *)
   return param1
end customFunctionName

set theresult to customFunctionName("a", "b")
-- in "tell" block, have to prepend function call with "my"

Select an incognito window in Brave:

tell application "Brave Browser"
     activate
     repeat with w in windows
         if mode of w is "incognito" then
            set index of w to 1
            exit repeat
         end if
     end repeat
end tell

If a variable is defined:

property something : ""

if something is ""
   set something to "Actual value"
end

To see what you can “tell” the application, locate .sdef files, and in library (Shift-Command-L in Script Editor), add the .app containing the sdef file.

Template for quicksilver actions:

(*
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