【问题标题】:Applescript progress bar not workingApplescript 进度条不起作用
【发布时间】:2016-08-02 19:40:11
【问题描述】:

我有一个正常工作的进度条码,但是当我将它与一些任务混合使用时,比如在这里复制文件,它给了我错误并且不会增加,它在第一次复制后停止,知道问题出在哪里吗?

代码如下:

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.您是否将其保存为小程序? 2.也许Finder的选择只包含你点击后的脚本?在重复之前创建display dialog x as string 以确保 3. 告诉我们更多关于您遇到的错误。
  • 我将它保存为应用程序,它只是在第一个之后停止,这是你可以运行它并查看错误的整个脚本
  • 如何启动脚本?您是否尝试过我回答的第 2 点?
  • 我从脚本编辑器运行脚本,并且我确定查找器选择包含文件而不是脚本,您是否在您的机器上尝试过此代码?
  • 好的,请双击启动应用程序!但在您的第一个 tell application Finder 之后添加 activate 之前

标签: macos applescript


【解决方案1】:

这是脚本,请阅读下面的注释

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"-Block,因为应用程序“Finder”不知道进度条,并更正了目标文件夹以匹配任何桌面文件夹。现在完美运行,如果

  • 脚本保存为小程序
  • 小程序通过 Dock 启动

这是因为

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

  • 如果您通过在 Finder 中双击来启动 Applet,Applet 本身就会成为选择,因为您单击它!从扩展坞启动它可以解决这个问题!

玩得开心,迈克尔/汉堡

【讨论】:

  • 实际上目标文件夹只是一个占位符,无论如何我都必须将其更改为其他位置,我使用此脚本的目的是将其放入服务中,以便我可以通过右键单击选定的文件,我会试试你的解决方案
  • 我可以在 Mail 中执行某些操作的应用程序中使用它,并且不需要我从 Dock 中打开它。我确实与脚本需要的用户进行了一些交互,这使邮件应用程序成为焦点,所以也许这就是原因。 Mail 不像 Finder 那样识别进度指示器,因此必须退出 Tell Mail 才能使其正常工作。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2018-10-19
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多