AppleScript Tips

Finder
iTunes
URL Access Scripting
InternetExplorer(2003.9.21 -updated)
Appearance (デスクトップピクチャ関連)
文字列操作、その他






Finder

・ドラッグ&ドロップしたファイルの file type & file creator を調べる

on open theFile
tell application "Finder"
select theFile
display dialog "ファイルタイプ:" & file type of selection & return & "クリエータ:" & creator type of selection
end tell
end open


iTunes

・ドラッグ&ドロップしたファイルをmp3に変換する( mp3 ファイルは iTunes フォルダ内に作られる)

on open theFile
tell application "iTunes"
activate
set theFile to theFile as text
ignoring application responses
convert theFile
end ignoring
end tell
end open

・ライブラリ内の曲をランダムにかける

tell application "iTunes"
launch
set minimized of browser windows to true -- ウィンドウを小さくする
set listName to name of library playlist 1
set t_num to count track of library playlist listName
if t_num >= 1 then
set r_num to random number from 1 to t_num
play track r_num of library playlist listName
end if
end tell

・指定したプレイリスト内の曲をランダムにかける

tell application "iTunes"
launch
set listName to "Favorite list" -- プレイリストの名前
set minimized of browser windows to true
set ex_list to ""
repeat with h from 1 to (count user playlist)
if name of user playlist h is listName then set ex_list to "exsist list"
end repeat
if ex_list is "exsist list" then
set t_num to count track of user playlist listName
if t_num >= 1 then
set r_num to random number from 1 to t_num
play track r_num of user playlist listName
end if
end if
end tell


URL Access Scripting

・指定したURLのファイルをスクリプトと同じフォルダにダウンロードする

set fileUrl to "http://〜〜" -- ダウンロードするファイルのURL
set defDel to AppleScript's text item delimiters
set AppleScript's text item delimiters to "/"
set l_item to last text item of fileUrl
set AppleScript's text item delimiters to defDel
if last item of fileUrl is "/" then
set f_name to "download.html" -- ファイル名がない時はファイル名を"download.html"にする
else
set f_name to last text item of l_item
end if
tell application "Finder" to set m_path to path to me as text
set AppleScript's text item delimiters to ":"
set l_path to last text item of m_path
set AppleScript's text item delimiters to defDel
set Num to (offset of l_path in m_path)
set destination to strings 1 thru (Num - 1) of m_path & f_name
tell application "URL Access Scripting"
activate
try
download fileUrl to file destination replacing no -- replacing yes で同名のファイルがある場合に置き換える
on error
display dialog "error"
end try
quit
end tell



InternerExplorer

・ニュース、天気、google検索、本の検索結果をIEで開く



Appearance (デスクトップピクチャ関連)

・指定したURLのファイルをダウンロードし、壁紙に設定する
・Internet Explorer で開いている画像ファイルをダウンロードし、壁紙に設定する
・選択中のフォルダ内から画像をランダムに選んで壁紙に設定する



文字列操作、その他

・ドロップしたテキストファイルから単語を適当に抽出、別ファイルで保存



Homeに戻る