我正在编写一个程序,它不断地将桌面背景设置为在 iTunes 中播放的当前歌曲的专辑封面,为此,我将艺术作品写入具有随机 ID 号的文件。这意味着桌面每次都会更改为不同的文件。
当然,我希望能够在使用完所有这些文件后删除它们,因此我尝试使用do shell script "rm ~rf " & folderName
删除包含图像的整个文件夹。
但是,每次我运行我的脚本甚至在终端中输入完整目录时,我都会收到错误消息:
“rm:〜rf:没有这样的文件或目录rm:Macintosh:没有这样的文件或目录rm:HD:Users:BenClose:Desktop:iTunesWallpaper:没有这样的文件或目录”
下面是我整个程序的代码,我不知道哪里出了问题,所以任何帮助都将不胜感激,因为我希望任何希望它能够使用这个程序的人。
screenNum
指正在更改的桌面。
hiddenFile
指创建的文件是否会被隐藏。"."
if true and ""
if false(添加到文件名开头的句点将使其隐藏)。
基本上,正在发生的事情是桌面背景被设置为专辑封面 99 次,之后我希望能够删除所有 99 个文件并让该过程重新开始。
该错误发生在脚本的最后,它试图删除图像文件夹。
set screenNum to 2
set directoryName to "iTunesWallpaper"
set fileExt to "jpg"
set hiddenFile to ""
set repeatTrue to 1
set loopLimit to 99
set looped to 0
set folderName to ((path to desktop) as text) & hiddenFile & directoryName
repeat while repeatTrue is 1
tell application "Finder"
if (exists folderName) is not true then
make new folder at (path to desktop) as text with properties {name:hiddenFile & directoryName}
end if
end tell
set randID to screenNum
set randLoop to 0
repeat while randLoop is not 9
set randNum to (random number from 0 to 9) as text
set randID to randID & randNum
set randLoop to randLoop + 1
end repeat
tell application "System Events"
set fileName to {((path to desktop) as text) & hiddenFile & directoryName & ":" & randID & "." & fileExt}
set changeDesktop to 0
if process "iTunes" exists then
tell application "iTunes"
if (player state is not stopped) then
if exists artworks of current track then
set changeDesktop to 1
-- get the raw bytes of the artwork into a var
tell application "iTunes" to tell artwork 1 of current track
set srcBytes to raw data
end tell
-- write to file
set outFile to open for access file fileName with write permission
-- truncate the file
set eof outFile to 0
-- write the image bytes to the file
write srcBytes to outFile
close access outFile
end if
end if
end tell
if changeDesktop = 1 then
if exists desktop screenNum then
tell desktop screenNum
set picture to fileName
end tell
end if
end if
end if
end tell
set looped to looped + 1
if looped is loopLimit then
do shell script "rm ~rf " & folderName
set looped to 0
end if
end repeat