Reputation:
I want to open an app(.app) from a bash shell(.sh using #!/usr/bin/bash) which is located in a folder in /Applications. How do I open it?
If I can open it, can I close it? If yes, how?
Upvotes: 3
Views: 9614
Reputation: 11
of course you can do that, please use the terminal command "open".
#!/bin/bash
echo This is a play music script
# play Music from command line in the background
open ~/Downloads/AlanWalker-Faded.m4a &
# wait some seconds
sleep 60
# force quit iTunes
killall iTunes
Upvotes: -1
Reputation: 25042
Setting your shebang to #!/usr/bin/env bash
(which is the preferred way as it's portable), consider the following examples:
Utilize open
command with the -a
option. For instance:
open -a "Safari"
Or, using osascript
to execute an AppleScript. For instance:
osascript -e 'tell application "Safari" to activate'
Or a terse equivalent:
osascript -e 'activate app "Safari"'
Utilize osascript
to execute an AppleScript. For instance:
osascript -e 'tell application "Safari" to quit'
Or a terse equivalent:
osascript -e 'quit app "Safari"'
Note: If bash
actually resides in /usr/bin/
on macOS as per your question the above examples will work successfully with the shebang: #!/usr/bin/bash
Upvotes: 9