我正在尝试自动删除使用Photoshop生成的PNG文件(或许多文件)的预览图标。
我知道如何手动执行此操作:我可以选择文件,按命令+ shift + i,选择该窗口上的图标并点击删除键删除文件;但是我更喜欢用AppleScript(或者我将用do shell
命令嵌入我的AppleScript中的终端命令)自动执行此操作...我在网上搜索了好几天,但我发现没有任何帮助我
那么,有没有人知道可以用来删除PNG(或JPEG)文件的预览图标的AppleScript或终端命令?
答案 0 :(得分:2)
您可以使用setIcon
类中的NSWorkspace
方法删除文件的图标。 https://developer.apple.com/library/mac/documentation/Cocoa/Reference/ApplicationKit/Classes/NSWorkspace_Class/
Cocoa-AppleScript小程序
use framework "AppKit"
use scripting additions
set myFiles to choose file with prompt "Select PNG files" with multiple selections allowed
set sharedWk to current application's NSWorkspace's sharedWorkspace()
repeat with tFile in myFiles
(sharedWk's setIcon:(missing value) forFile:(POSIX path of tFile) options:0)
end repeat
使用执行shell脚本
的AppleScriptset pyScript to quoted form of "from AppKit import NSWorkspace; import sys; NSWorkspace.sharedWorkspace().setIcon_forFile_options_(None, sys.argv[1].decode('utf-8'), 0)"
set myFiles to choose file with prompt "Select PNG files" with multiple selections allowed
repeat with tFile in myFiles
do shell script "/usr/bin/python -c " & pyScript & " " & (quoted form of POSIX path of tFile)
end repeat
以下是一些链接:
https://en.wikipedia.org/wiki/Cocoa_(API)
https://developer.apple.com/library/mac/releasenotes/ScriptingAutomation/RN-AppleScriptObjC/
https://en.wikipedia.org/wiki/PyObjC
使用Objective-C Bridge的JavaScript - > https://developer.apple.com/library/mac/releasenotes/InterapplicationCommunication/RN-JavaScriptForAutomation/Articles/OSX10-10.html