【问题标题】:Creating an automator service to create a new document in the current directory创建自动化服务以在当前目录中创建新文档
【发布时间】:2012-08-24 10:04:00
【问题描述】:

所以我正在尝试创建一个服务,该服务将位于 Finder 的上下文菜单中,并允许在当前目录中创建一个新文档。

我一直在使用 Automator 执行此操作: 抱歉一切都是法语^^

无论如何,这是我用来检索当前工作目录的 AppleScript:

on run {input, parameters}
    tell application "Finder"
        set pwdAlias to insertion location as alias
        if not (exists folder pwdAlias) then
            set pwdAlias to (container of pwdAlias) as alias
        end if
    end tell
    set pwd to POSIX path of pwdAlias
    return pwd
end run

然后我将此值设置为一个变量,然后使用该变量作为文档的路径创建一个新的文本文档,最后我在 Finder 中使用命令 Reveal 来显示创建的文档。

一切正常,只是脚本似乎总是迟到! 我的意思是,当我打开一个新的 Finder 窗口并选择我的服务时,它正在系统地在前一个窗口上创建文档,如下所示:

但是,如果我再次尝试,文档将在预期位置正确创建:

这是非常系统的,每次都会发生!

对不起,如果我不是很清楚,解释起来并不容易!

否则,我正在运行 Mountain Lion,这是随附的 Automator 项目:create_new_document

要添加服务,只需解压缩并将文件放在 ~/Library/Services/ 下即可

希望得到一些答案,但我担心这只是一个 Automator 错误!

【问题讨论】:

  • 顺便说一句,您的服务链接已损坏!
  • 我编写并更新了教程如何使用自动机filipmolcik.com/new-file-mac-os将此选项放入上下文菜单中

标签: macos applescript finder automator


【解决方案1】:

试试这个

  • 取决于您要点击的内容。

将选择的服务设置为:'文件夹' 或文件或文件夹。在“Finder.app”中

  • 获取第一个 Finder 窗口路径操作

您可以从my blog post here 下载获取第一个 Finder 窗口路径操作 下载地址在帖子的bottom。 Action 获取最前面的finder 窗口的posix 路径。 由于您正在单击窗口中的文件夹。该窗口将是返回的窗口。

  • 设置变量值

  • 获取指定文本

下一个动作“新建文本文件”需要一些输入。如果它没有得到任何文件,则不会创建任何文件。您可以将文本字段保留为空白。只需采取适当的行动即可。

  • 新建文本文件

将变量“路径”或您命名的任何内容拖到“位置:”下拉菜单中。

您可以单击 Automator 窗口底部的双蓝线来切换工作流变量列表

保存您的服务。试试看。 (可能需要一段时间才能显示在上下文菜单中。)

【讨论】:

【解决方案2】:

这是open bug in 10.7 and 10.8

使用此解决方法

on run {input, parameters}
    activate application "System Events"
    activate application "Finder"
    tell application "Finder"
        set pwdAlias to insertion location as alias
        set pwdAlias to (container of pwdAlias) as alias
    end tell
    return POSIX path of pwdAlias
end run

【讨论】:

  • 您好,感谢您的快速回复!好吧,我已经尝试过该脚本,但它给了我非常随机的结果;我正在尝试在“我的文档”中创建一个文档,并且该文档正在我的用户文件夹中创建〜。所以我通过使用来自输入的路径来做这件事有点不同:set pwd to (the POSIX path of first item of input)。它不像我希望的那样通用,但它正在做这项工作!
猜你喜欢
  • 2012-12-17
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2011-07-30
  • 2010-12-17
  • 2015-08-04
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多