简体   繁体   中英

Applescript progress bar not working

I have a properly working progress bar code but when I mix it with some tasks, like copying files here, it gives me error and does not increment, it stops after the first copy, any idea where is the problem?

Here is the code:

tell application "Finder"
    set selected_items to selection
    set fileCount to length of selected_items
end tell

set progress total steps to fileCount
set progress completed steps to 0
set progress description to "Processing Images..."
set progress additional description to "Preparing to process."
set a to 1

tell application "Finder"
    set theFolder to POSIX file "/Users/graphics/Desktop/1"
    repeat with x in selected_items
        set progress additional description to "Processing image " & a & " of " & fileCount
        duplicate x to theFolder
        set progress completed steps to a + 1
        set a to a + 1
    end repeat
end tell

Here's the script, please read the notes below :

tell application "Finder"
    set selected_items to selection
    set fileCount to count of selected_items
end tell

set progress total steps to fileCount
set progress completed steps to 0
set progress description to "Processing Images..."
set progress additional description to "Preparing to process."
set a to 1

repeat with x in selected_items
    set progress additional description to "Processing image " & a & " of " & fileCount
    tell application "Finder"
        set theFolder to (path to desktop folder as string) & "1:"
        duplicate x to theFolder with replacing
    end tell
    tell me to set progress completed steps to a + 1
    set a to a + 1
end repeat

I moved the set progress... handlers out of the tell application "Finder" -Block because the application "Finder" does not know about the progress bar, and corrected the target folder to match any desktop folder. It works perfectly now, if

  • The Script is saved as Applet
  • The Applet is started via the Dock

This is because

  • Script Editor cannot take care about the different thread for updating the progress bar when running inside Script Editor

  • If you start the Applet via doubleclick inside the Finder, the Applet itself becomes the selection, just because you click it! Starting it from the dock solves this issue!

Have fun, Michael / Hamburg

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM