Macos 创建自动机服务以在当前目录中创建新文档
因此,我正在尝试创建一个服务,该服务将位于Finder的上下文菜单中,并允许在当前目录中创建一个新文档 我一直在使用Automator: 对不起,所有的都是法语^^ 无论如何,下面是我用来检索当前工作目录的AppleScript:Macos 创建自动机服务以在当前目录中创建新文档,macos,applescript,finder,automator,Macos,Applescript,Finder,Automator,因此,我正在尝试创建一个服务,该服务将位于Finder的上下文菜单中,并允许在当前目录中创建一个新文档 我一直在使用Automator: 对不起,所有的都是法语^^ 无论如何,下面是我用来检索当前工作目录的AppleScript: on run {input, parameters} tell application "Finder" set pwdAlias to insertion location as alias if not (exists fo
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
然后我将这个值设置为一个变量,然后使用这个变量作为文档的路径创建一个新的文本文档,最后我使用命令discover in Finder来显示创建的文档
一切都很顺利,除了脚本似乎总是很晚!
我的意思是,当我打开一个新的Finder窗口并选择我的服务时,它会在上一个窗口中系统地创建文档,如下所示:
但是,如果我再次尝试,文档将在预期位置正确创建:
这是非常系统的每次都会发生
对不起,如果我不是很清楚,这不是那么容易解释
除此之外,我正在运行Mountain Lion,下面是所附的Automator项目:
要添加服务,只需解压缩并将文件放在~/Library/Services下/
希望得到一些答案,但我担心这只是一个自动程序错误 这是一个
使用此解决方法
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
试试这个
- 取决于您要单击的内容
- 获取第一个查找器窗口路径操作
- 设置变量的值
- 获取指定的文本
- 新文本文件
(可能需要一段时间才能显示在上下文菜单中。)嘿,感谢您的快速回复!我试过那个脚本,但它给了我随机的结果;我正在尝试在我的文档中创建一个文档,该文档正在我的用户文件夹中创建~。因此,通过使用输入的路径,我的做法有点不同:
将pwd设置为(第一项输入的POSIX路径)
。它不像我希望的那样通用,但它正在发挥作用!顺便说一句,你的服务链接断了!我编写并更新了如何使用automator将此选项放入上下文菜单的教程,请参见