我在Dock的右侧有一个文件夹,我希望能够通过命令行将其删除(我最终会将其添加到AppleScript脚本中)。
是否有用于从Dock中删除文件夹的命令行工具?
编辑:我找到了这个脚本,它通过右键单击一个标题为"Airdrop“的文件夹,单击”Options“,然后单击”Remove from Dock“,将其从我的dock中删除
tell application "System Events" to tell UI element "AirDrop" of list 1 of application process "Dock"
perform action "AXShowMenu"
click menu item "Options" of menu 1
click menu item "Remove from Dock" of menu 1 of menu item "Options" of menu 1
end tell但是,因为它使用UI脚本,所以在运行脚本时,将出现如下图所示的rick-click菜单。
当我运行脚本时,有什么方法可以防止这个菜单出现在我的屏幕上吗?

发布于 2019-12-16 12:33:38
下面的脚本可以从dock中移除命名文件夹的dock磁贴。目前,它被设置为删除Downloads文件夹的停靠磁贴,如果有的话。
use framework "Foundation"
use framework "AppKit"
property this : a reference to the current application
property NSArray : a reference to NSArray of this
property NSMutableDictionary : a reference to NSMutableDictionary of this
property NSPredicate : a reference to NSPredicate of this
property NSPropertyList : a reference to NSPropertyListSerialization of this
property NSRunningApplication : a reference to NSRunningApplication of this
property NSString : a reference to NSString of this
property BinaryPList : 200
property id : "com.apple.dock"
property file : "~/Library/Preferences/" & id & ".plist"
property key : "persistent-others"
property keys : [key, "tile-data", "file-label", "lowercaseString"]
removeDockTileFolder("Downloads")
if the result = true then return killDock()
false
to removeDockTileFolder(directory as text)
local directory
set filepath to (NSString's ¬
stringWithString:(my file))'s ¬
stringByStandardizingPath()
tell (NSMutableDictionary's dictionaryWithContentsOfFile:filepath)
tell valueForKeyPath_((NSArray's ¬
arrayWithArray:(keys as list))'s ¬
componentsJoinedByString:".")
set N to |count|()
set i to indexOfObject_((NSString's ¬
stringWithString:directory)'s ¬
lowercaseString())
if i ≥ N then return false
end tell
valueForKey_(my key)'s removeObjectAtIndex:i
tell (NSPropertyList's dataFromPropertyList:it ¬
format:BinaryPList errorDescription:(missing value)) ¬
to writeToFile:filepath atomically:yes
end tell
end removeDockTileForFolder
to killDock()
(runningApplicationsWithBundleIdentifier_(my id) ¬
in the NSRunningApplication)'s terminate
true
end killDock成功时返回true;失败时返回false (提供的名称与任何文件夹停靠磁贴的名称都不匹配)。
https://stackoverflow.com/questions/59345726
复制相似问题