I’ve got a quick apple script that I’ve turned into an application that will swap my dock from hidden at the bottom to always visible on the right-side. I run this script every morning when I get to work and plug in to a 2nd monitor and before I leave in the afternoon before I yank the cord. Is there some system event I can watch for with a launch daemon to fire off this script automatically when the system detects a change such as isExternalMonitor = True/False? I’m running Monterey on a M1MBP if that matters.
ps I don’t want to use a timed launchd because my schedule isn’t set enough to M-F@7 just run this thing.
Thanks for any help,~Sauva
<3 I’d never heard of hammerspoon, but check it, I made it work!
this is toggle doc.app
tell application "System Events"
set monitorCount to count of desktops
if monitorCount is 1 then
tell dock preferences
set properties to {screen edge:bottom}
set autohide to true
end tell
else
tell dock preferences
set properties to {screen edge:right}
set autohide to false
end tell
end if
end tell
this is my hammerspoon init.lua
--init.lua
--using hammerspoon to automatically run toggledock
-- LOAD VARIABLES
monitorWatcher = nil
initWatcher = nil
--MY FUNCTIONS
--function to reload init.lua when it changes
function reloadConfig(files)
doReload = false
for _,file in pairs(files) do
if file:sub(-4) == ".lua" then
doReload = true
end
end
if doReload then
hs.reload()
end
end
--need a function that calls an applescript
function monitorChangedCallback()
-- hs.alert.show("trying to call toggle dock.app")
hs.application.launchOrFocus("toggle dock.app")
end
--TOP
--starts the pathwatcher to see if the init.lua changes in ~/.hammerspoon/
initWatcher = hs.pathwatcher.new(os.getenv("HOME") .. "/.hammerspoon/", reloadConfig):start()
hs.alert.show("Config loaded")
--objects will be garbage collcted if they aren't in explicit vars
--Starts the screen watcher, making it so fn is called each time the screen arrangement changes
monitorWatcher = hs.screen.watcher.new(monitorChangedCallback):start()
Thanks a bunch for turning me onto this sylumer
~~Sauva