【问题标题】:Automator "Get specified finder items" applescript equivalentAutomator“获取指定的查找器项目”applescript等效
【发布时间】:2013-04-20 16:41:42
【问题描述】:

我有一些我想通用的例程:在描述文件夹路径时,我想坚持用户当前用户(“~/”),而不是选定的文件夹。

所以我的问题是,如果我在 automator 中选择一个带有“Get Specified Finder Items”的文件夹,它会输出一个像这样的 -non applescript- 列表:(“path/to/my/folder”),我该如何复制它与applescript。注意圆括号而不是大括号!

首先我只是想用这个:

on run
  return {"~/path/to/my/folder/under/current/user"}
end run

然后我会添加“获取文件夹内容”块..

谁能告诉我为什么这不起作用? 提前致谢!

【问题讨论】:

  • 当然,列表中会有更多文件夹。这就是为什么我首先需要一个列表。

标签: applescript automator


【解决方案1】:

好吧,我还是把我正在为你打的东西贴出来吧:-)

set folderTest1 to "test1"
set folderTest2 to "test2"


set homePath to POSIX path of (path to home folder as text) as text
set attachmentsFolder to (homePath & folderTest1 & "/" & folderTest2) as text

--OR


set homePath to POSIX path of (path to home folder as text) as text
set attachmentsFolder to (homePath & "test1/test2") as text

POSIX PATH 将 HFS+ 路径更改为 unix 类型路径

home 文件夹的路径 到用户的 home 文件夹

文档路径获取用户文档文件夹的路径

POSIX 文件将 unix 类型路径更改为 HFS+ 路径

set homePath to POSIX path of (path to home folder as text) as text


set theHFSPath to (POSIX file homePath)
tell application "Finder"
    --The finder looks for the folders in the alais path of theHFSPath
    set theFolders to folders of (theHFSPath as alias) as alias list

    --> returns is a list of folders in the form of alais paths

end tell

【讨论】:

  • 我最终用以下语法解决了它:return {alias ((path to home folder as text) & "Library:Caches:Adobe Camera Raw" as text)} Ans 因为这是在我的自动化应用程序的“运行 AppleScript”块中,所以我只是附加了“获取文件夹内容”和“移动查找器” Items toTrash" 块。这样它是通用的,我可以将它发送给同事。
【解决方案2】:

我用下面的代码解决了:

on run
return { POSIX path of ((path to home folder as text)) & "/path to my folder" as text, .. }
end run

【讨论】:

  • 可以缩短为{(system attribute "HOME") & "/path to my folder"}。脚本有一个隐式运行处理程序,它们返回最后一个值。 system attribute "HOME" 与 $HOME 相同。
  • 我最终用以下语法解决了它:return {alias ((path to home folder as text) & "Library:Caches:Adobe Camera Raw" as text)} Ans 因为这是在我的自动化应用程序的“运行 AppleScript”块中,所以我只是附加了“获取文件夹内容”和“移动查找器” Items toTrash" 块。这样它是通用的,我可以将它发送给同事。
猜你喜欢
  • 2016-12-19
  • 1970-01-01
  • 1970-01-01
  • 2015-05-08
  • 1970-01-01
  • 1970-01-01
  • 2011-12-28
  • 2020-04-30
  • 1970-01-01
相关资源
最近更新 更多