如何创建新的文件列表并返回它们?

发布于 2024-12-19 02:30:00 字数 937 浏览 3 评论 0原文

我在 Automator 工作流程中使用以下 AppleScript:

on run {input, parameters}
  --say input
  set result_array to {} as list
  try
      repeat with this_file in input
          tell application "Image Events"
              launch
              set this_image to open this_file
              copy dimensions of this_image to {W, H}
              close this_image
          end tell

          set text item delimiters to ":"
          set file_name to last text item of (this_file as string)
          set text item delimiters to ""
          set filter_string to W & "x" & H as string

          if file_name contains filter_string then
              set the end of result_array to this_file
          end if
  end repeat
  return result_array
  on error error_message
      display dialog error_message
  end try
end run

该脚本在 获取文件夹内容 操作之后运行。

结果数组有问题,但我不知道是什么问题。 结果必须是名称中包含大小的文件列表。

I'm using the following AppleScript in my Automator workflow:

on run {input, parameters}
  --say input
  set result_array to {} as list
  try
      repeat with this_file in input
          tell application "Image Events"
              launch
              set this_image to open this_file
              copy dimensions of this_image to {W, H}
              close this_image
          end tell

          set text item delimiters to ":"
          set file_name to last text item of (this_file as string)
          set text item delimiters to ""
          set filter_string to W & "x" & H as string

          if file_name contains filter_string then
              set the end of result_array to this_file
          end if
  end repeat
  return result_array
  on error error_message
      display dialog error_message
  end try
end run

The script runs after a Get Folder Contents action.

There is something wrong with the result array but I can't figure out what.
The result has to be a list of files which have their size in their names.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

沐歌 2024-12-26 02:30:00

如果我理解正确,请使用以下之一:

if file_name contains filter_string then
 -- set the end of result_array to this_file as alias
 -- set the end of result_array to this_file as text
end if

当前 this_file 就像指向原始文件列表的指针。直接使用时,它包括当前值的索引和完整列表。

这可能是由于Applescript 中repeat with a in b 的实现方式所致。

If I understood correctly use one of the following :

if file_name contains filter_string then
 -- set the end of result_array to this_file as alias
 -- set the end of result_array to this_file as text
end if

Currently this_file is like a pointer to the original list of files. When used directly it includes the index of the current value and the full list.

This is probably due to how the repeat with a in b is implement in Applescript.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文