Close and Re-open Script
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Posted on 03-20-2018 03:04 PM
I would like to create a script to close google Chrome and then Re-open the program .
I have tried using :
pkill -a -i "Google Chrome"
#!/bin/bash
loggedInUser=`python -c 'from SystemConfiguration import SCDynamicStoreCopyConsoleUser; import sys; username = (SCDynamicStoreCopyConsoleUser(None, None, None) or [None])[0]; username = [username,""][username in [u"loginwindow", None, u""]]; sys.stdout.write(username + "
");'`
su -l $loggedInUser -c "open -a "Google Chrome""
This closes the application successfully but the re-opening portion is not working which is the second half of this script.
Any help is appreciated.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Posted on 03-20-2018 05:05 PM
Use an osascript call.
/usr/bin/osascript<<END
tell application "Google Chrome"
open
end tell
END
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Posted on 03-21-2018 05:33 AM
Hi, why do you need to run this as loggedInUser and su? I would make this:
#!/bin/bash
pkill -a -i "Google Chrome"
open -a Google Chrome
but if you want do run as su and loggedInUser then it working so:
#!/bin/bash
pkill -a -i "Google Chrome"
loggedInUser=`python -c 'from SystemConfiguration import SCDynamicStoreCopyConsoleUser; import sys; username = (SCDynamicStoreCopyConsoleUser(None, None, None) or [None])[0]; username = [username,""][username in [u"loginwindow", None, u""]]; sys.stdout.write(username + "
");'`
su -l $loggedInUser -c "open -a Google Chrome"
The mistakes is here, your script look like so:
su -l $loggedInUser -c "open -a "Google Chrome""
and have to be so:
su -l $loggedInUser -c "open -a Google Chrome"
or so:
su -l $loggedInUser -c "open -a 'Google Chrome'"
