tabs - Applescript - 打开一个新标签
问题描述
我的 AppleScript 能力相当有限,所以请原谅可能是一个简单的问题。
我将此脚本作为 Automator 服务,它将在新窗口中打开一系列别名。
由 Finder 中的键盘命令通过首选项>键盘>快捷方式>服务触发。
服务在 Finder 中接收选定的文件或文件夹
on run {input, parameters}
repeat with aFile in input
tell application "Finder"
try
set origFile to original item of aFile
set aWindow to make new Finder window
set aWindow's target to origFile's parent
select origFile
end try
end tell
end repeat
end run
我想尝试在选项卡中打开,最好不要求助于 GUI 脚本。
set aWindow to make new Finder window
似乎没有等价物,并且在set aWindow to make new Finder tab
Apple 的在线文档中搜索“make”或“tab”已被证明是毫无结果的……或者相当多的水果,所有错误的品种:/
我有另一个来源的 GUI 版本
on new_tab()
tell application "System Events" to tell application process "Finder"
set frontmost to true
tell front menu bar to tell menu "File" to tell menu item "New Tab"
perform action "AXPress"
end tell
end tell
end new_tab
所以,如果直接方法失败,我怎么能把它折叠到我现有的脚本中?
macOS 10.13.4
解决方案
未选中在选项卡中打开文件夹而不是Finder中的新窗口首选项的macOS 默认设置,以及打开文档时的Dock首选项Prefer tabs:在System Preferences设置为In Full Screen Only中,以下示例AppleScript代码应该可以正常工作通过合并您的原始AppleScript代码和处理程序的代码。 new_tab
on run {input, parameters}
set madeNewWindow to false
repeat with i from 1 to count input
tell application "Finder"
if (kind of item i of input) is equal to "Alias" then
set origFile to original item of item i of input
if not madeNewWindow then
set theWindow to make new Finder window
set madeNewWindow to true
else
my makeNewTab()
end if
set theWindow's target to origFile's parent
select origFile
end if
end tell
end repeat
end run
on makeNewTab()
tell application "System Events" to tell application process "Finder"
set frontmost to true
tell front menu bar to tell menu "File" to tell menu item "New Tab"
perform action "AXPress"
end tell
end tell
end makeNewTab
在我的系统上,我没有必要使用该
delay
命令,但是,您的系统上可能需要也可能不需要命令,如果需要,请在适当调整值的同时根据delay
需要添加。编码用于Automator服务中的Run AppleScript 操作,其中Service 在 [Finder] 中接收选定的 [文件或文件夹]。
需要将Finder添加到System Preferences中Security & Privacy下的Accessibility中。
在 macOS High Sierra 下测试。
注意:示例AppleScript 代码 就是这样,并没有采用任何其他错误处理,然后显示的内容仅用于显示完成任务的多种方法之一。用户始终有责任根据需要/想要 添加/使用适当的错误处理。
推荐阅读
- android - Android数据绑定在打开其他应用后停止工作
- networking - 域控制器名称中可以使用句点(。)吗?
- c++ - 未使用 STL 向量分配被释放的指针(仅限 OS X)
- swift4 - 搜索过滤器未在集合视图中更新。当我键入一个值 A 时,它的资产在搜索中键入另一个值后显示
- c++ - 使用 Qt 的 RESTful API 请求
- elasticsearch - ElasticSearch 错误请求
- excel - 将 Excel 模板的 VBA 代码插入新工作簿后无法正常工作
- corda - custom logging does not works when set in systemProperties
- jsf - p:datatable 列的标题
- ansible - 进行模板复制时出现“目标目录不存在”错误