Desired Workflow
I would like to have a button on my SD XL open Safri, but if Safari is already open, then quit Safari. (Or any app.)
Question
How can I make a launch/quit application toggle?
Command Info
ID: user:ckbh254mu00003t10obrbnu93:ckc276x6a0002bk10d0zje6rb
Name: Launch Safari
Source
undefined
Links
User UID: I7doJ14mp3dUHDwLh8NxCBcVqcK2
Feedback Key: sffeedback:I7doJ14mp3dUHDwLh8NxCBcVqcK2:-MBB0yM-lm4ePnMEjz1A
- Christian Scheuer @chrscheuer2020-07-02 13:26:25.565Z
Hi John.
You'll need the bundle ID as well as the path to the application to do this.
const appBundleId = 'com.apple.Safari'; const appPath = '/Applications/Safari.app'; var app = sf.ui.app(appBundleId); if (app.exists) sf.system.execAppleScript({ script: `quit app "${appPath}"` }); else sf.system.exec({ commandLine: `open -a "${appPath}"` });
John Costello @John_Costello
Wow! Works perfect! I am very new to scripting but I see the unlimited potential. Thank you Christian!
John Costello @John_Costello
Hello Christian!
I have learned how to find bundle ID's using the terminal. I have been able to adapt this script to many other apps, making for a great universal launch/quit streamdeck layout. But for some reason I can't make it work with apple apps like mail, notes, messages. Any help would be greatly appreciated. Thank you!
John Costello @John_Costello
I figured out that the path name for some apple applications are:
System/Applications/mail
This adapts Christians script very nicely indeed.
- In reply tochrscheuer⬆:SSeverin Ahn @Severin_Ahn
Hi Christian, I'm trying to do this with the "Audio-Midi-Setup" app but can't get it to work. This is what I have. Any suggestions?
const appBundleId = 'com.apple.audio.AudioMIDISetup'; const appPath = '/Applications/Utilities/Audio-MIDI-Setup.app';
var app = sf.ui.app(appBundleId);
if (app.exists) sf.system.execAppleScript({ script:
quit app "${appPath}"}); else sf.system.exec({ commandLine:
open -a "${appPath}"});
Christian Scheuer @chrscheuer2021-05-18 18:55:12.083Z
Hi Severin. At first glance: Your path to the app is wrong - it should have regular spaces in place of dashes :)
Christian Scheuer @chrscheuer2021-05-18 18:59:23.828Z
The easiest way to get the correct path is to select the app in Finder and hit Option+Cmd+C, then paste the path into SF :)
- SIn reply toJohn_Costello⬆:Severin Ahn @Severin_Ahn
That already solved it! Thanks!