I am using following applescript
to relaunch finder application.
osascript -e "tell application \"Finder\"" -e "delay 1" -e "try" -e "quit" -e "delay 1" -e "activate" -e "end try" -e "end tell"
But sometimes this script is not relaunching finder application(only quiting finder application). i am not getting any error in console.
http://www.cocoabuilder.com/archive/cocoa/113654-nsapplescript-buggy.html
Can anyone please help me out?
Here's an applescript way. You cannot rely on a specific delay time as you've seen. Therefore we manually wait for the Finder to quit by checking if it's in the list of running processes. When it is no longer in the list then we know it has quit and we can activate it again.
You'll also note I put a time check in the script because of the repeat loop. Just in case something goes wrong we do not want the repeat loop to run forever. As such if it runs for more than 10 seconds we automatically exit the repeat loop.
tell application "Finder" to quit
set inTime to current date
repeat
tell application "System Events"
if "Finder" is not in (get name of processes) then exit repeat
end tell
if (current date) - inTime is greater than 10 then exit repeat
delay 0.2
end repeat
tell application "Finder" to activate
Here's the osascript version of that code.
/usr/bin/osascript -e 'tell application "Finder" to quit' -e 'set inTime to current date' -e 'repeat' -e 'tell application "System Events"' -e 'if "Finder" is not in (get name of processes) then exit repeat' -e 'end tell' -e 'if (current date) - inTime is greater than 10 then exit repeat' -e 'delay 0.2' -e 'end repeat' -e 'tell application "Finder" to activate'