Benches macOS

3

Applescript Ignoring Timeout

apple Verified

Imported from the Apple Support Forums via the Wayback Machine 🔗

Hi Guys,

Long time listener, first time caller. I have cobbled this script together from other posts. It is designed to close all open applications with exceptions and rsync a directory to a removable drive. Unfortunately the script times out after some hours when rsyncing some large files (>~40 gig).

Script Below

--------------------------------------------------------------------------------

set userCancelled to false

with timeout of 86400 seconds -- one day

display dialog "Do you want to Sync and Shutdown? " & "" buttons {"No", "Yes"} with icon caution with title "Backup" default button "Yes"

if button returned of result = "Yes" then

tell application "System Events" to set the visible of every process to true

set white_list to {"Finder", "AppleScript Editor", "Mail", "Address Book", "iCal", "Things", "Skype"}

try

tell application "Finder"

set process_list to the name of every process whose visible is true

end tell

repeat with i from 1 to (number of items in process_list)

set this_process to item i of the process_list

if this_process is not in white_list then

tell application this_process

quit

end tell

end if

end repeat

on error

tell the current application to display dialog "An error has occurred!" & return & "This script will now quit" buttons {"Quit"} default button 1 with icon 0

end try

set {weekday:d} to (current date)

set date_format to d as string

display dialog date_format & "Syncing starts in 5 seconds…

This operation may takes few minutes." with icon note buttons {"OK"} with title "Backup" giving up after 5

do shell script "rsync -avE –delete-after ~/Library/VirtualBox/ /Volumes/Daily_Backup/Backup/VirtualBox/" & date_format & "/ > ~/rsync.log || echo -n"

-- do shell script "rsync -avE –delete-after ~/Documents/ /Volumes/Daily_Backup/Backup/Documents/" & date_format & "/ > ~/rsync.log || echo -n"

--display dialog "Backup completed Do you want to see the log?" with icon note buttons {"No", "Yes"} with title "Backup" default button "Yes" giving up after 10

--if button returned of result = "Yes" then

-- tell application "Finder" to open file "rsync.log" of home

--end if

try

set answer to display dialog "Backup complete. Shutting down in 30 seconds." giving up after 30

on error number -128

set userCancelled to true

end try

if userCancelled then

else if gave up of answer then

tell application "Finder"

shut down

end tell

end if

end if

end timeout

--------------------------------------------------------------------------------

Script Above

It does take any longer than 24 hours and if there is nothing or little to rsync the script executes without an issue.

I have seen other posts but none of their suggestions seem to help.

Please HELP.... it is really frustrating me though I am sure I have done something stupid.

Thanks,

Will

3 replies

Sign in or join Beachball Help to reply.

  1. 0

    nate12345

    Imported from the Apple Support Forums via the Wayback Machine 🔗

    I haven't heard of the with timeout command before, but I found
    this post that might be of interest.

    "With timeout tells AppleScript how long it should wait for an application to respond to any command it's given."

    I'm not sure if that's what you were intending, but it wasn't what I had expected.

    Anyway, helpful or not, good luck!

    -Nate

  2. 0

    Will_Schey

    Imported from the Apple Support Forums via the Wayback Machine 🔗

    Hi Nate,

    Thanks for the reply. I had seen this article. and Yes, that is the behaviour I am expecting to see. My Rsync command is going to take a few hours to complete. So I allow it 24 hrs before Applescript expects a response but it times out after only a few hours, well short of the 24 hrs.

    I think it may be the way I am using the timeout, but who knows.

    Thanks again.

    Regards,

    Will

  3. 0

    red_menace

    Imported from the Apple Support Forums via the Wayback Machine 🔗

    From the
    AppleScript Language Guide: "A +with timeout+ statement applies only to commands sent to application objects, not to commands sent to the application that is running the script". As far as I can tell, since it would be the current application (the script) that ultimately executes the +do shell script+ command, +with timeout+ would not be applied - for example, if you perform an
    ls command on a large volume/directory with a short timeout, the script does not time out:

    with timeout of 10 seconds
    do shell script "ls -lR /Library; echo 'done'"
    end timeout
    activate me
    display dialog "done"

    I'm not sure where the ultimate timeout is coming from, but you might try another approach, such as testing the result log or capturing the error with a
    try statement.