在当前目录下创建一个新文档的自动化服务

9

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

我正在使用Automator进行操作:

Automator project

不好意思,所有内容都是法语^^

无论如何,这里是我用来检索当前工作目录的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中显示”命令显示已创建的文档。

除了脚本似乎总是延迟之外,一切都运行正常!我的意思是,当我打开一个新的Finder窗口并选择我的服务时,它总是在前一个窗口上创建文档,如下所示: Selecting Create a new document The document is created at the wrong location

但是如果我再试一次,那么文档就会被正确地创建到预期位置: Trying again to create a new document This time the document is created properly!

而且这非常系统化,每次都会发生!!

抱歉,如果我表达得不太清晰,这不是很容易解释!

另外,我正在运行Mountain Lion,并附有Automator项目: create_new_document

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

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


1
顺便说一下,你服务的链接挂了! - markhunte
1
我编写并更新了有关如何使用自动化程序将此选项添加到上下文菜单的教程。https://filipmolcik.com/new-file-mac-os - Filip Molcik
https://www.youtube.com/watch?v=sE_V0vzNTWQ - KcFnMi
2个回答

7

试一下enter image description here

  • 根据您想要点击的内容

将所选服务设置为:'文件夹'或文件或文件夹。在 'Finder.app' 中

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

您可以从我的博客文章中下载获取第一个Finder窗口路径操作。 下载位于帖子底部。 该操作获取最前面的查找器窗口的posix路径。 由于您正在单击窗口中的文件夹。返回的将是该窗口。

  • 设置变量值

  • 获取指定文本

下一个操作“新建文本文件”需要一些输入。如果没有任何输入,将不会创建任何文件。您可以将文本字段留空。只需放置操作即可。

  • 新建文本文件

将变量'path'或您命名的任何内容拖放到“位置:”下拉菜单上。

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

workflow Variable List

保存您的服务。然后试一下。 (可能需要一段时间才能出现在上下文菜单中。)


请参见http://superuser.com/questions/106943/os-x-snow-leopard-finder-automator-item-for-creating-a-new-text-file。 - mems

3

这是在10.7和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)。这不像我想要的那样通用,但它正在完成工作! - guitio2002

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接