简体   繁体   English

Applescript进度条不起作用

[英]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. 我将set progress...处理程序移出了tell application "Finder" -Block,因为应用程序“Finder”不知道进度条,并更正了目标文件夹以匹配任何桌面文件夹。 It works perfectly now, if 如果 ,它现在完美地工作

  • The Script is saved as Applet 脚本保存为Applet
  • The Applet is started via the Dock Applet通过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! 如果你通过在Finder中双击启动Applet,Applet本身就成了选择,只因为你点击它! Starting it from the dock solves this issue! 从码头开始解决了这个问题!

Have fun, Michael / Hamburg 玩得开心,迈克尔/汉堡

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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