[英]macOS Terminal (or AppleScript) - Remove folder from Dock
I have a folder on the right side of the Dock that I'd like to be able to remove via the command line (which I will ultimately add into an AppleScript script).我在 Dock 的右侧有一个文件夹,我希望能够通过命令行删除它(我最终将添加到 AppleScript 脚本中)。
Is there a command line utility for removing a folder from the Dock?是否有用于从 Dock 中删除文件夹的命令行实用程序?
Edit: I found this script, which removes a folder titled "Airdrop" from my dock by right-clicking on it, clicking Options
, and then clicking Remove from Dock
编辑:我找到了这个脚本,它通过右键单击我的 Dock 中一个名为“Airdrop”的文件夹,单击
Options
,然后单击Remove from 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
However, because it uses UI scripting, the rick-click menu appears as shown in the image below, when the script is run.但是,因为它使用 UI 脚本,所以当脚本运行时,rick-click 菜单如下图所示。
Is there someway to prevent this menu from showing up on my screen when I run the script?当我运行脚本时,有什么办法可以防止这个菜单出现在我的屏幕上吗?
The script below can remove a named folder's dock tile from the dock.下面的脚本可以从 Dock 中删除命名文件夹的 Dock 磁贴。 Currently, it is set to remove the Downloads folder's dock tile, provided there is one.
目前,它被设置为删除下载文件夹的停靠栏,前提是有一个。
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
Returns true
upon success;成功时返回
true
; false
upon failure (the supplied name did not match the name of any of the folder dock tiles).失败时为
false
(提供的名称与任何文件夹停靠图块的名称都不匹配)。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.