-
-
Notifications
You must be signed in to change notification settings - Fork 93
@LuisWollenschneider's config
I use ⌘ + . as my LeaderKey
I wanted some extra behaviour instead of just opening an application and started using the command action alongside some AppleScripts to further customise my keybinds.
This is a striped configuration to highlight some of the more custom commands
{
"actions" : [
{
"key" : "s",
"label" : "Safari",
"type" : "command",
"value" : "osascript ~/LeaderKeyScripts/safari.scpt"
},
{
"key" : "v",
"label" : "VS Code",
"type" : "command",
"value" : "osascript ~/LeaderKeyScripts/vscode.scpt"
},
{
"key" : "c",
"label" : "ChatGPT",
"type" : "command",
"value" : "osascript ~/LeaderKeyScripts/safari.scpt https://chatgpt.com"
},
{
"actions" : [
{
"key" : "t",
"label" : "Terminal",
"type" : "command",
"value" : "osascript ~/LeaderKeyScripts/terminal.scpt"
},
{
"key" : "p",
"label" : "python",
"type" : "command",
"value" : "osascript ~/LeaderKeyScripts/terminal.scpt python3"
},
{
"key" : "s",
"label" : "ssh",
"type" : "command",
"value" : "osascript ~/LeaderKeyScripts/terminal.scpt \"ssh some_machine\""
}
],
"key" : "t",
"label" : "Terminal",
"type" : "group"
}
],
"type" : "group"
}I typically want a new window when using any of the shortcuts instead of a new tab, thus this script can also open specified URLs, but inside a new window. Also, if no specific URL is provided, the clipboard is checked for a URL as well
-- Open Safari
-- Usage: `osascript path/to/safari.scpt [url]`
-- Open a new Safari window with the provided URL
-- if no URL is provided, open a new window with the current clipboard url
-- if the URL is not valid, open a new window
on run argv
if (argv is not {}) then
-- command line URL
set targetUrl to item 1 of argv
else
-- clipboard URL
set targetUrl to the clipboard as string
end if
tell application "Safari"
-- validate URL (bare minimum)
if targetUrl starts with "http://" or targetUrl starts with "https://" then
make new document with properties {URL:targetUrl}
else
-- no / invalid URL -> open a new window
make new document at end of documents
end if
activate
end tell
end runOpening a specific folder inside the terminal from the finder is a common thing for me, hence the script checks for any open "Finder" windows and opens a new window at the specific path.
One can also provide a shell command directly to be executed. I have a python shell shortcut, which simply invokes python3 in a new window.
Also helpful to quickly connect to a machine via ssh
-- Usage: `osascript path/to/terminal.scpt [command]`
-- Open Terminal
-- if a command is provided, execute the command in a new window
-- if no command is provided, and a Finder window is open, open the Terminal in the current folder
-- if no Finder window is open, bring the Terminal to the front
-- if no Terminal window is open, create a new one
on run argv
tell application "Terminal"
-- if no window is open, create a new one
set new_window to true
if (count of windows) is 0 then
do script ""
set new_window to false
end if
if argv is not {} then
if new_window is true then
-- open a new window
do script ""
delay 0.1
end if
-- execute clear command | makes it look nicer, otherwise it will show the following command twice
do script "clear" in front window
do script item 1 of argv in front window
else
set currentFolder to ""
tell application "Finder"
if exists front window then
set currentFolder to POSIX path of (target of front window as alias)
end if
end tell
if currentFolder is not "" then
do script "cd " & currentFolder in front window
do script "clear" in front window
end if
end if
activate
end tell
end runSimilar behaviour to the terminal command, however if a Finder window is opened, and the path is part of a git repository, open the root directory instead. And if no Finder path is found, an entirely new window is created.
-- Open Visual Studio Code at the git root folder or current Finder folder if no git repo
-- Usage: `osascript path/to/vscode.scpt`
set gitBinPath to "/usr/bin/git"
set codeBinPath to "/usr/local/bin/code"
set currentFolder to ""
tell application "Finder"
if exists front window then
-- get the current folder from opened Finder window
set currentFolder to POSIX path of (target of front window as alias)
-- if git repo
if (do shell script "cd " & currentFolder & " && " & gitBinPath & " rev-parse --is-inside-work-tree") is "true" then
-- get the git root folder
set currentFolder to do shell script "cd " & currentFolder & " && " & gitBinPath & " rev-parse --show-toplevel"
end if
end if
end tell
tell application "Visual Studio Code"
if currentFolder is not "" then
-- open the folder
do shell script codeBinPath & " " & currentFolder
else
-- If no folder is open, just open a new window
do shell script codeBinPath & " -n"
end if
end tell