Skip to content

Instantly share code, notes, and snippets.

@ilikepi
Last active December 24, 2023 06:11
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ilikepi/9d2e17e0d3b3efd6fc0584f46f099b88 to your computer and use it in GitHub Desktop.
Save ilikepi/9d2e17e0d3b3efd6fc0584f46f099b88 to your computer and use it in GitHub Desktop.
macOS Automator script to force Firefox to always boot with ProfileManager
on run {input, parameters}
tell application "Finder"
set ffxAppPath to POSIX path of (application file id "org.mozilla.firefox" as string)
end tell
set ffxBinaryName to "firefox"
set ffxExePath to ffxAppPath & "/Contents/MacOS/" & ffxBinaryName
-- Command to start a new instance of Firefox Profile Manager in the background
-- and return its pid.
set ffxCmd to ffxExePath & " -P -no-remote > /dev/null 2>&1 & echo $!"
-- Polling parameters, used to determine for how long (in seconds) the script will wait
-- for the new Firefox instance to launch.
set pollInterval to 0.15
set maxWaitTime to 5
-- Launch the new instance of Firefox and capture its pid.
do shell script ffxCmd
set newFfxPid to (the result as integer)
-- Wait a reasonable amount of time for the new instance to become visible,
-- so we can bring it to the foreground.
repeat maxWaitTime / pollInterval times
tell application "System Events"
set allFfxPids to unix id of processes whose name is ffxBinaryName
end tell
-- Once the new process is running, short-circuit the loop.
if allFfxPids contains newFfxPid then
tell application "System Events"
set frontmost of the first process whose unix id is newFfxPid to true
end tell
exit repeat
end if
delay pollInterval
end repeat
return input
end run
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment