Applescript进度条不起作用

时间:2016-07-30 10:03:03

标签: macos applescript

我有一个正常工作的进度条形码但是当我把它与某些任务混合在一起时,比如在这里复制文件,它会给我错误并且不会增加,它会在第一个副本之后停止,任何想法在哪里出现问题?

以下是代码:

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

1 个答案:

答案 0 :(得分:2)

这是脚本,请阅读以下注释

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

我将set progress...处理程序移出tell application "Finder" - 阻止因为应用程序" Finder"不知道进度条,并更正目标文件夹以匹配任何桌面文件夹。现在效果很好,如果

  • 脚本保存为Applet
  • Applet通过 Dock
  • 启动

这是因为

  • 在脚本编辑器中运行时,脚本编辑器无法处理用于更新进度条的不同线程

  • 如果您通过在Finder中双击启动Applet,Applet本身就会成为选择,只因为您点击它!从码头开始解决了这个问题!

玩得开心,迈克尔/汉堡