Last active
December 24, 2023 06:11
-
-
Save ilikepi/9d2e17e0d3b3efd6fc0584f46f099b88 to your computer and use it in GitHub Desktop.
macOS Automator script to force Firefox to always boot with ProfileManager
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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