Skip to content

Commit

Permalink
Add System Preferences selection & update defaults
Browse files Browse the repository at this point in the history
- Update System Preferences entity and add to default select mode events
- Add Volumes folder to default file events
- Add disk utility application entity
  • Loading branch information
andweeb committed Feb 17, 2019
1 parent ed6120e commit 728e158
Show file tree
Hide file tree
Showing 4 changed files with 218 additions and 0 deletions.
4 changes: 4 additions & 0 deletions src/defaults.lua
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ local entities = {
Calculator = _G.requirePackage("entities/calculator", true),
Contacts = _G.requirePackage("entities/contacts", true),
Dictionary = _G.requirePackage("entities/dictionary", true),
DiskUtility = _G.requirePackage("entities/disk-utility", true),
FaceTime = _G.requirePackage("entities/facetime", true),
Finder = _G.requirePackage("entities/finder", true),
GoogleChrome = _G.requirePackage("entities/google-chrome", true),
Expand Down Expand Up @@ -87,6 +88,7 @@ function Defaults.createFileEvents()
{ nil, "m", File:new("~/Movies"), { "Files", "Movies" } },
{ nil, "p", File:new("~/Pictures"), { "Files", "Pictures" } },
{ nil, "t", File:new("~/.Trash"), { "Files", "Trash" } },
{ nil, "v", File:new("/Volumes"), { "Files", "Volumes" } },
{ { "cmd" }, "a", openFinderAppEvent("Airdrop"), { "Files", "Airdrop" } },
{ { "cmd" }, "c", openFinderAppEvent("Computer"), { "Files", "Computer" } },
{ { "cmd" }, "i", openFinderAppEvent("iCloud\\ Drive"), { "Files", "iCloud Drive" } },
Expand Down Expand Up @@ -129,6 +131,7 @@ function Defaults.createEntityEvents()
{ nil, "t", entities.Terminal, { "Entities", "Terminal" } },
{ nil, "v", entities.VoiceMemos, { "Entities", "Voice Memos" } },
{ nil, ",", entities.SystemPreferences, { "Entities", "System Preferences" } },
{ { "cmd" }, "d", entities.DiskUtility, { "Entities", "Disk Utility" } },
{ { "alt", "cmd" }, "s", entities.Siri, { "Entities", "Siri" } },
{ { "shift" }, "a", entities.ActivityMonitor, { "Entities", "Activity Monitor" } },
{ { "shift" }, "c", entities.Calculator, { "Entities", "Calculator" } },
Expand All @@ -153,6 +156,7 @@ function Defaults.createEntityEvents()
{ nil, "p", entities.Preview, { "Select Events", "Select a Preview window" } },
{ nil, "s", entities.Safari, { "Select Events", "Select a Safari tab or window" } },
{ nil, "t", entities.Terminal, { "Select Events", "Select a Terminal window" } },
{ nil, ",", entities.SystemPreferences, { "Entities", "Select a System Preferences pane" } },
{ { "shift" }, "t", entities.TextEdit, { "Select Events", "Select a Text Edit window" } },
}

Expand Down
15 changes: 15 additions & 0 deletions src/entities/disk-utility.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
local Application = dofile(_G.spoonPath.."/application.lua")

local actions = {
newBlankImage = Application.createMenuItemEvent("Blank Image...", { focusAfter = true }),
newImageFromFolder = Application.createMenuItemEvent("Image From Folder...", { focusAfter = true }),
openDiskImage = Application.createMenuItemEvent("Open Disk Image...", { focusAfter = true }),
}

local shortcuts = {
{ nil, "n", actions.newBlankImage, { "File", "New Blank Image" } },
{ nil, "o", actions.openDiskImage, { "File", "Open Disk Image" } },
{ { "shift" }, "n", actions.newImageFromFolder, { "File", "New Image From Folder" } },
}

return Application:new("Disk Utility", shortcuts), shortcuts, actions
41 changes: 41 additions & 0 deletions src/entities/system-preferences.lua
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,48 @@ local actions = {
showAllPreferences = Application.createMenuItemEvent("Show All Preferences", { focusBefore = true }),
}

function Application.getSelectionItems()
local choices = {}
local script = Application.renderScriptTemplate("system-preferences", { option = "fetch-panes" })
local isOk, panes, rawTable = hs.osascript.applescript(script)

if not isOk then
Application.notifyError("Error fetching System Preferences panes", rawTable.NSLocalizedFailureReason)
end

for paneId, paneName in pairs(panes) do
table.insert(choices, {
paneId = paneId,
text = paneName,
subText = paneId,
})
end

table.sort(choices, function(a, b)
return a.text < b.text
end)

return choices
end

function actions.focus(app, choice)
app:activate()

if choice then
local script = Application.renderScriptTemplate("system-preferences", {
option = "reveal-pane",
targetPane = choice.paneId,
})
local isOk, _, rawTable = hs.osascript.applescript(script)

if not isOk then
Application.notifyError("Error revealing System Preferences pane", rawTable.NSLocalizedFailureReason)
end
end
end

local shortcuts = {
{ nil, nil, actions.focus, { "View", "Activate/Focus" } },
{ nil, "l", actions.showAllPreferences, { "View", "Show All Preferences" } },
{ { "cmd" }, "f", actions.search, { "View", "Search" } },
}
Expand Down
158 changes: 158 additions & 0 deletions src/osascripts/system-preferences.applescript
Original file line number Diff line number Diff line change
@@ -0,0 +1,158 @@
-- AppleScript template for various system preferences options
-- `option` - the name of the option
-- `targetPane` - the target pane to reveal
set option to "{{option}}"
set targetPane to "{{targetPane}}"

tell application "System Preferences"

if option is "fetch-panes" then

set paneIdsByName to {}

repeat with prefPane in panes
set paneId to id of prefPane
set paneName to name of prefPane as string

set AppleScript's text item delimiters to {return & linefeed, return, linefeed, character id 8233, character id 8232}
set paneName to text items of paneName
set AppleScript's text item delimiters to {" "}
set paneName to paneName as text

set paneRecord to run script "{|" & paneId & "|:\"" & (paneName as string) & "\"}"
set paneIdsByName to paneIdsByName & paneRecord
end repeat

return paneIdsByName

else if option is "reveal-pane" then

reveal pane targetPane

else if option is "Accessibility" then

reveal pane "com.apple.preference.universalaccess"

else if option is "Bluetooth" then

reveal pane "com.apple.preferences.bluetooth"

else if option is "Date & Time" then

reveal pane "com.apple.preference.datetime"

else if option is "Desktop & Screen Saver" then

reveal pane "com.apple.preference.desktopscreeneffect"

else if option is "Displays" then

reveal pane "com.apple.preference.displays"

else if option is "Dock" then

reveal pane "com.apple.preference.dock"

else if option is "Energy Saver" then

reveal pane "com.apple.preference.energysaver"

else if option is "Extensions" then

reveal pane "com.apple.preferences.extensions"

else if option is "General" then

reveal pane "com.apple.preference.general"

else if option is "iCloud" then

reveal pane "com.apple.preferences.icloud"

else if option is "Internet Accounts" then

reveal pane "com.apple.preferences.internetaccounts"

else if option is "Keyboard" then

reveal pane "com.apple.preference.keyboard"

else if option is "Language & Region" then

reveal pane "com.apple.localization"

else if option is "Mission Control" then

reveal pane "com.apple.preference.expose"

else if option is "Mouse" then

reveal pane "com.apple.preference.mouse"

else if option is "Network" then

reveal pane "com.apple.preference.network"

else if option is "Notifications" then

reveal pane "com.apple.preference.notifications"

else if option is "Parental Controls" then

reveal pane "com.apple.preferences.parentalcontrols"

else if option is "Printers & Scanners" then

reveal pane "com.apple.preference.printfax"

else if option is "Security & Privacy" then

reveal pane "com.apple.preference.security"

else if option is "Sharing" then

reveal pane "com.apple.preferences.sharing"

else if option is "Siri" then

reveal pane "com.apple.preference.speech"

else if option is "Software Update" then

reveal pane "com.apple.preferences.softwareupdate"

else if option is "Sound" then

reveal pane "com.apple.preference.sound"

else if option is "Spotlight" then

reveal pane "com.apple.preference.spotlight"

else if option is "Startup Disk" then

reveal pane "com.apple.preference.startupdisk"

else if option is "Time Machine" then

reveal pane "com.apple.prefs.backup"

else if option is "Touch ID" then

reveal pane "com.apple.preferences.password"

else if option is "Trackpad" then

reveal pane "com.apple.preference.trackpad"

else if option is "Users & Groups" then

reveal pane "com.apple.preferences.users"

else if option is "Wallet & Apple Pay" then

reveal pane "com.apple.preferences.wallet"

end if

end tell

0 comments on commit 728e158

Please sign in to comment.