デスクトップの背景を iTunes で現在再生中の曲のアルバム アートに継続的に設定するプログラムを作成しています。そのために、ランダムな ID 番号を持つファイルにアートワークを書き込んでいます。これは、デスクトップが毎回別のファイルに変更されることを意味します。
もちろん、使用後にこれらのファイルをすべて削除できるようにしたいのでdo shell script "rm ~rf " & folderName
、画像を含むフォルダー全体を削除するために使用しようとしています。
ただし、スクリプトを実行するたびに、またはターミナルに完全なディレクトリを入力するたびに、次のエラーが表示されます。
「rm: ~rf: そのようなファイルまたはディレクトリはありません rm: Macintosh: そのようなファイルまたはディレクトリはありません rm: HD:Users:BenClose:Desktop:iTunesWallpaper: そのようなファイルまたはディレクトリはありません」
以下は私のプログラム全体のコードです。何がどこで間違っているのかわかりません。そのため、このプログラムを使用できるようにしたい人なら誰でも使用できるようにしたいので、どんな助けでも大歓迎です。
screenNum
どのデスクトップが変更されているかを示します。
hiddenFile
作成されたファイルが非表示になるかどうかを示します。"."
true の""
場合と 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