我有一个脚本,用您选择的图像更改文件夹的图标,它工作正常但我希望能够让脚本自动选择文件夹的第一个图像并将其指定为将成为的图像用于创建图标。
这是我到目前为止所拥有的。根据我的尝试,它无法选择图像并提供各种错误消息。任何帮助将不胜感激!
set exePath to (path to home folder as text) & "downloads:SetFileIcon"
tell application "Finder"
set theSelection to selection -- This is a list of selected items, even if only 1 item is selected.
set theFile to (item 1 of theSelection) as text -- Get the first item in the list. We make it text so we can convert it to a posix path for SetFileIcon.
set theimage to item 1 of theSelection
set imagePath to (path to desktop folder as text) and theimage
end tell
do shell script quoted form of POSIX path of exePath & " -image " & quoted form of POSIX path of imagePath & " -file " & quoted form of POSIX path of theFile
答案 0 :(得分:0)
乍一看你的剧本有几个问题。首先,你永远不会要求文件夹的内容。您将theFile
设置为item 1 of theSelection
,然后将theimage
设置为item 1 of theSelection
。我希望你的意思是将theimage
设置为document files of theFile
的第1项。请注意,theFile
实际上是所选文件夹。
其次,“和”是一个布尔运算;要在AppleScript中连接文本,请使用“& ”。因此,即使theimage
包含图片的名称,您也需要使用& theimage
。
但是,由于您要求Finder获取信息,Finder已经知道任何特定文件的完整路径。因此,一旦获得图像,您可以直接向Finder询问路径。
tell application "Finder"
-- This is a list of selected items, even if only 1 item is selected.
set theSelections to the selection
-- This code assumes that the first selected item is a folder
set theFolder to the first item of theSelections
-- we want the first document that is also an image
set theImages to the document files of theFolder whose kind contains "image"
set theImage to item 1 of theImages as text
-- and we want it's path
set imagePath to POSIX path of theImage
end tell