Skip to content

Instantly share code, notes, and snippets.

@vitorgalvao
vitorgalvao / Get Title and URL.applescript
Last active July 19, 2024 10:51
AppleScript and JavaScript for Automation to get frontmost tab’s url and title of various browsers.
-- AppleScript --
-- This example is meant as a simple starting point to show how to get the information in the simplest available way.
-- Keep in mind that when asking for a `return` after another, only the first one will be output.
-- This method is as good as its JXA counterpart.
-- Webkit variants include "Safari", "Webkit", "Orion".
-- Specific editions are valid, including "Safari Technology Preview".
-- "Safari" Example:
tell application "Safari" to return name of front document
@vitorgalvao
vitorgalvao / Prevent Dropbox Password Dialog.md
Last active June 6, 2024 08:47
Prevent Dropbox password dialog

If you don’t give Dropbox your password, it pesters you on startup. You can avoid that by setting 0000 permissions on the Dropbox.app/Contents/Resources/DropboxHelperInstaller.tgz file, but that only lasts until the next Dropbox update. To make it permanent, we install a launchd job which will watch that file for changes and reset the permissions as we want them.

If you have Dropbox installed somewhere other than /Applications/Dropbox.app, edit the plist accordingly.

Install

mkdir -p "${HOME}/Library/LaunchAgents"
curl 'https://gist.githubusercontent.com/vitorgalvao/f0bac70751004e0d3d1ef6b88b51f6e9/raw/5c9bb853d85f9da99d7e4b89e18e0f6d8a5321c4/com.vitorgalvao.launchd.preventdropboxdialog.plist' --output "${HOME}/Library/LaunchAgents/com.vitorgalvao.launchd.preventdropboxdialog.plist"
launchctl bootstrap "gui/$(id -u "${USER}")" "${HOME}/Library/LaunchAgents/com.vitorgalvao.launchd.preventdropboxdialog.plist"
@vitorgalvao
vitorgalvao / Open New Tab In Specific Browser.js
Created February 11, 2023 19:01
JavaScript for Automation (JXA) for opening a new tab in different browsers
// JavaScript for Automation (JXA) for opening a new tab in different browsers.
// Doing an "open 'https://example.com/'" and letting macOS handle it is usually preferable,
// but sometimes you want to specifically open a tab in a browser which is not the default.
// Chromium-based browsers
// Other examples include "Brave Browser", "Vivaldi"
const browser = Application("Google Chrome")
const newTab = browser.Tab({ url: "https://example.com/" })
@vitorgalvao
vitorgalvao / Right Click.applescript
Last active March 16, 2023 14:30
Make right-clicking on OSX accessible via a keyboard shortcut
(*
A [native solution][1] exists but it suffers from a major flaw: it right-clicks where the cursor is, not what on the selection.
This code addresses that limitation, though it only works on Finder windows and not the Desktop.
You can install it as a [Finder Service, and later asign it a keyboard shortcut][2].
[1]: http://stackoverflow.com/questions/9171613/right-click-shortcut-for-mac-lion-os
[2]: http://www.macosxautomation.com/services/learn/tut01/index.html
*)