[英]Applescript Folder Action not working
我寫了一個Applescript,它將監視文件夾中是否有新輸入。 收到新項目后,它將打開iTunes,創建播放列表,然后將新文件添加到播放列表中。 但是,當我通過“文件夾操作設置”將腳本作為“文件夾操作”附加並添加新項目時,什么也沒有發生。 我已將該腳本放在/ Library / Scripts / Folder Action Scripts以及〜/ Library / Scripts / Folder Action Scripts中,但仍不會觸發。 這是我的代碼如下:
global album_name
global artist_album
on adding folder items to this_folder after receiving added_items
--get the name of the added folder
repeat with x in added_items
copy name of x as string to playlist_name
set AppleScript's text item delimeters to "-"
set delimited_playlist_name to every text item of playlist_name
set artist_name to text item 1 of delimited_playlist_name
set album_name to text item 2 of delimited_playlist_name
set AppleScript's text item delimeters to ""
end repeat
tell "Finder" to activate "iTunes"
tell application "iTunes"
if not (exists playlist album_name) then
--make iTunes playlist
make playlist with properties {name:album_name}
--add the tracks to the iTunes playlist
repeat with song in playlist_name
add song to playlist album_name
set album of song to album_name
set artist of song to artist_name
set comment of song to ""
set composer of song to ""
set grouping of song to ""
set description of song to ""
set long description of song to ""
set (volume adjustment) of song to 100
end repeat
set view of browser window to album_name
end if
end tell
end adding folder items to
我正在運行Mac OS 10.8.4
在將來
display dialog
條目,以查看進行的程度和發生的情況。 因此,假設問題出在您的代碼上,我將其重寫為一個簡單的Applescript,並使其在我的Snow Leopard(10.6.8)系統上工作。
它也可以從Automator內部作為文件夾動作正常運行,並帶有“運行Applescript動作”項中的代碼。 從Automator內部保存后,它確實會在將新文件添加到文件夾並運行ok時激活。
PS:由於您未提供任何詳細信息,因此我不得不從您的代碼中猜測出您要嘗試執行的操作。 這遠非最佳,但它將帶您前進...
高溫超導
# remove this line for Applscript Action in Automator...
set input to (choose file with multiple selections allowed)
set playlist_name to {}
#display dialog "Delimeter set to -"
set AppleScript's text item delimiters to "-"
repeat with x in input
#display dialog "Item: " & (x as text)
tell application "Finder"
set fl to name of x
display dialog "Filename: " & fl
end tell
# bring back focus to the editor ## TESTING ONLY
activate me
# append item to the list
copy (fl as text) to the end of playlist_name
display dialog "Playlist count: " & length of playlist_name
set artist_name to text item 1 of fl
display dialog "Artist: " & artist_name
set album_name to text item 2 of fl
display dialog "Album: " & album_name
end repeat
#display dialog "Activating iTunes..."
#activate "iTunes"
#display dialog "iTunes activated!"
tell application "iTunes"
if not (exists playlist album_name) then
display dialog "Making new playlist: " & album_name
make playlist with properties {name:album_name}
display dialog "Changing view..."
set view of browser window 1 to playlist album_name
# add the tracks to the iTunes playlist
repeat with song in input
display dialog "Adding: " & song
set newtrack to (add song to playlist album_name)
set album of newtrack to album_name
set artist of newtrack to artist_name
set comment of newtrack to ""
set composer of newtrack to ""
set grouping of newtrack to ""
set description of newtrack to ""
set long description of newtrack to ""
set (volume adjustment) of newtrack to 100
end repeat
else
display dialog "iTunes playlist already exists!"
end if
end tell
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.