You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I cannot currently use these as my MacBook is too old and limited to Sonoma. However, I want to preserve some code I've written for it.
Consider checking for the most updated code before importing this.
Setup instructions:
#### Safari web apps
macOS Sonoma introduced a feature called [Safari web apps][] which are macOS' implementation of a generic feature called a [site-specific browser][]. While [Firefox](https://pwasforfirefox.filips.si/) and [Google Chrome](https://support.google.com/chrome/answer/9658361?sjid=12950535267183201417-NC) also support variants of this, I've found the native macOS implementation to work best.
To create the web apps, open the following sites in Safari:
-[Gmail](https://mail.google.com/)
First, log into the site. Safari web apps use the favicon as the app icon, so we need to be logged in for the correct favicon to load.
After logging into to the site, click **File > Add to Dock…**. For the name, use the exact name in the list above. Accept the default icon and URL.
Repeat this for every site in the list.
[Safari web apps]: https://support.apple.com/en-us/104996[site-specific browser]: https://en.wikipedia.org/wiki/Site-specific_browser
From Hammerspoon init.lua:
-- Helpful stuff:-- https://github.com/Hammerspoon/hammerspoon/issues/1025-- https://github.com/Hammerspoon/hammerspoon/issues/664pasteboardWatcher=hs.pasteboard.watcher.new(function(pasteboardContents)
pasteboardWatcher:stop()
-- Do not use hs.pasteboard.readURL; it does not do what you think it does!ifpasteboardContentsthenhs.urlevent.openURL(pasteboardContents)
elsehs.alert.show("Pasteboard contents were not a valid string")
endend)
-- Select Copy Link and open the URL from the pasteboard when we ⌘-Click in the given applicationsleftClickWatcher=hs.eventtap.new({hs.eventtap.event.types.leftMouseUp}, function(event)
ifnotevent:getFlags():containExactly({"⌘"}) thenreturnfalse-- Propagate eventendpasteboardWatcher:start()
hs.timer.doAfter(
2, function()
ifpasteboardWatcher:running() thenhs.alert.show("Timed out waiting for pasteboard contents")
pasteboardWatcher:stop()
endend)
-- TODO Is there a way to do this without using UI automation?-- Once we right-click, the menu is delayed in appearing. Thus we do not want to post the key strokes to navigate the context menu immediately. I have tried and it doesn't work well.hs.timer.doAfter(
0.1, function()
functionmodKeyStroke(modifiers, key)
-- TODO Add application parameter?hs.eventtap.keyStroke(modifiers, key, 0)
endfunctionkeyStroke(key)
modKeyStroke({}, key)
end-- Send a right arrow event. This will focus the first menu item but won't advance the selection.keyStroke("right")
-- Now jump down to the next sectionmodKeyStroke({"⌘"}, "down")
-- Now up one item to the Copy LinkkeyStroke("up")
keyStroke("return")
end)
-- Delete original event and post replacement right-click eventlocalreplacementEvents= {}
localmousePosition=hs.mouse.absolutePosition()
for_, typeinipairs({hs.eventtap.event.types.rightMouseDown, hs.eventtap.event.types.rightMouseUp}) dotable.insert(replacementEvents, hs.eventtap.event.newMouseEvent(type, mousePosition, {}))
endreturntrue, replacementEventsend)
-- https://www.lua.org/pil/11.5.htmlfunctionset(list)
localset= {}
for_, linipairs(list) doset[l] =trueendreturnsetend-- We don't use all these apps in every setup, but that's ok. It's simpler to keep them in the list and they won't be hurting anything.safariWebAppNames=set{"Gmail", "Google Chat", "Google Calendar", "Google Keep"}
deactivateEventTypes=set{hs.application.watcher.deactivated, hs.application.watcher.terminated}
hs.application.watcher.new(function(appName, eventType, hsApplication)
ifnotsafariWebAppNames[appName] thenreturnendifeventType==hs.application.watcher.activatedthenprint("Application " ..appName.." activated; starting left click watcher")
leftClickWatcher:start()
returnendifdeactivateEventTypes[eventType] thenprint("Application " ..appName.." deactivated; stopping left click watcher")
leftClickWatcher:stop()
returnend-- Ignore other event typesend):start()
The text was updated successfully, but these errors were encountered:
I cannot currently use these as my MacBook is too old and limited to Sonoma. However, I want to preserve some code I've written for it.
Consider checking for the most updated code before importing this.
Setup instructions:
From Hammerspoon
init.lua
:The text was updated successfully, but these errors were encountered: