You are not logged in.
Is there a better way to go about this. For some reason, if I do not close the safari application and restart it before continuing on with my script I run into several errors. Is there a better way to write this?
Applescript:
--If Safari is running close it & repoen it. If it is not running open it
tell application "System Events"
set Application_ID to (unix id of processes whose name is "Safari")
end tell
if Application_ID is not {} then
try
do shell script "kill -15 " & Application_ID
delay 2.0
tell application "Safari" to activate
tell application "System Events"
repeat until window 1 of process "Safari" exists
delay 0.005
end repeat
end tell
end try
else if Application_ID is {} then
tell application "Safari" to activate
tell application "System Events"
repeat until window 1 of process "Safari" exists
delay 0.005
end repeat
end tell
end if
Offline
Applescript:
tell application "System Events" to set isRunning to process "Safari" exists
tell application "Safari"
if isRunning then
quit
delay 0.5
end if
activate
end tell
Last edited by KniazidisR (2019-08-14 05:11:39 pm)
Model: MacBook Pro
OS X: Catalina 10.15.4
Web Browser: Safari 13.1
Ram: 4 GB
Offline
Guess I overcomplicated that... Thank you!
Offline
Still less complicated
Applescript:
tell application "Safari"
if it is running then
quit
delay 0.5
launch
end if
activate
end tell
Last edited by StefanK (2019-08-15 05:56:09 am)
regards
Stefan
Offline
Still less complicated
Yes, but would be better:
Applescript:
tell application "Safari"
if its running then
quit
delay 0.5
end if
activate
end tell
Last edited by KniazidisR (2019-08-15 06:19:11 am)
Model: MacBook Pro
OS X: Catalina 10.15.4
Web Browser: Safari 13.1
Ram: 4 GB
Offline
Even better, thank you both!
Offline
This reason is I put delay 0.5 second. I tested your script too. It requires for some reason bigger delay to avoid this error on my machine. My machine is slow, so to test on your machine, put some smaller delay on both scripts.
Last edited by KniazidisR (2019-08-15 11:10:40 am)
Model: MacBook Pro
OS X: Catalina 10.15.4
Web Browser: Safari 13.1
Ram: 4 GB
Offline
This script doesn't have to guess at the proper delay time; it waits until the app closes, then relaunches it. I've put the app name into a variable for generality...
Applescript:
set processName to "Safari"
tell application "System Events"
if exists process processName then
my quitIt(processName)
end if
repeat while (exists process processName)
delay 0.2
end repeat
my launchIt(processName)
end tell
on quitIt(processName)
tell application processName
quit
end tell
end quitIt
on launchIt(processName)
tell application processName
activate
end tell
end launchIt
Offline
Thanks, TedW. But this can be done easier:
Applescript:
tell application "Safari"
if its running then
quit
repeat while its running
delay 0.1
end repeat
end if
activate
end tel
OR:
Applescript:
my restart_App("Safari")
on restart_App(appName)
tell application appName
if its running then
quit
repeat while its running
delay 0.1
end repeat
end if
activate
end tell
end restart_App
Last edited by KniazidisR (2019-08-16 05:29:57 am)
Model: MacBook Pro
OS X: Catalina 10.15.4
Web Browser: Safari 13.1
Ram: 4 GB
Offline