tell application "System Events" set front_app to name of (path to frontmost application) set NUM to number of front_app set NUM to NUM - 4 set front_app to characters 1 thru NUM of front_app as text tell application front_app keystroke "l" using {command down} keystroke "c" using {command down} end tell end tell
tell application "Firefox" activate set page_title to the name of front window tell application "System Events" keystroke "l" using {command down} keystroke "c" using {command down} set page_URL to the clipboard as text end tell end tell
my gui_check() set temp to the clipboard as text tell application "Firefox" activate set page_title to the name of front window tell application "System Events" keystroke "l" using {command down} keystroke "c" using {command down} delay 0.5 set page_URL to the clipboard as text end tell end tell delay 0.5 set the clipboard to temp as text
to gui_check() tell application "System Events" if UI elements enabled is false then tell application "System Preferences" activate set current pane to pane "com.apple.preference.universalaccess" set msg to "GUI scripting is not available." & return & "Do you put the check in" & return & "\"Enable access for assistive devices\" ?" --display dialog msg buttons {"OK"} default button "OK" with icon note --giving up after 10 display dialog msg buttons {"cansel", "check and try"} with icon note end tell set UI elements enabled to true delay 0.5 tell application "System Preferences" to quit delay 0.5 end if end tell end gui_check
tell application "iTunes" set i_track to current track set i_name to the name of current track set i_artist to artist of current track set i_album to album of current track set i_genre to genre of current track set i_rating to rating of current track set i_lyrics to lyrics of current track set i_path to location of current track --HFSパス end tell
set bitly_user to "" --bit.ly ユーザー名 set bitly_api to "" --bit.ly API set longURL to "" --短縮前URL
to bitly(longURL, bitly_user, bitly_api) set inputResult to (longURL as string) if (((characters 1 thru 4 of inputResult) as string) = "http") then set curlCMD to "curl --stderr /dev/null \"http://api.bitly.com/v3/shorten?login=" & bitly_user & "&apiKey=" & bitly_api & "&longUrl=" & longURL & "&format=txt\"" set tinyURL to (do shell script curlCMD) return tinyURL end if end bitly
tell application "Finder" to repeat with a2 in selection as alias list copy properties of a2 to {name:a3, name extension:a4, container:a6} set a5 to a3's characters 1 thru -((count character of a4) + 2) as Unicode text set a7 to (a2 as alias) as Unicode text set a8 to POSIX path of a7 as Unicode text end repeat --a3:ファイル名&拡張子、a4:拡張子、a5:ファイル名、a6:ディレクトリ、a7:HFSパス、a8:POSIXパス
try set AppleScript's text item delimiters to "NewDelim" set DelList to "" repeat with i from 1 to (count text item of DelText) set demo to text item i of DelText set DelList to DelList & demo as list end repeat end try
--実行部 my growlRegister() growlNotify(grrTitle, grrDescription)
--サブルーチン部 using terms from application "GrowlHelperApp" on growlRegister() tell application "GrowlHelperApp" register as application "Tweet" all notifications {"Notification"} default notifications {"Notification"} icon of application "YoruFukurou.app" end tell end growlRegister on growlNotify(grrTitle, grrDescription) tell application "GrowlHelperApp" notify with name "Notification" title grrTitle description grrDescription application name "Tweet" end tell end growlNotify end using terms from
--チョチョイと設定 ここから --""内を変えるとSyntaxを変更できます set t to "t" --日付のSyntax set n to "n" --連番のSyntax set fol to "fol" --親フォルダのSyntax set cur to "cur" --現在のファイル名のSyntax set separator to "_" --各パラメータを区切る文字 set growl_run to "true" --いる場合は"true"、いらない場合は"false" --チョチョイと設定 ここまで
--フォルダ名取得 tell application "Finder" tell window 1 set parent_path to target as alias as text end tell try set oldDelim to AppleScript's text item delimiters set AppleScript's text item delimiters to ":" set parent_list to "" repeat with i from 1 to (count text item of parent_path) set demo to text item i of parent_path set parent_list to parent_list & demo as list end repeat end try set demo to count of parent_list set demo to demo - 1 set folder_name to text item demo of parent_list set AppleScript's text item delimiters to oldDelim end tell
--その他もろもろ set current_day to (do shell script "date '+%y%m%d'") set item_num to 0 set count_type to "" set current_type to "" set current_name to ""
--引数の判定と代入、count_typeとcurrent_typeは後の判定用 set my_parameter to q set my_parameter to my_parameter & "," & "," --引数が少ない時用 set oldDelim to AppleScript's text item delimiters set AppleScript's text item delimiters to ","
if text item 1 of my_parameter = t then set A to current_day else if text item 1 of my_parameter = n then set A to item_num set count_type to "A" else if text item 1 of my_parameter = cur then set A to "" set current_type to "A" else if text item 1 of my_parameter = fol then set A to folder_name else if text item 1 of my_parameter ≠ "" then set A to text item 1 of my_parameter else set A to "" end if
if text item 2 of my_parameter = t then set B to current_day else if text item 2 of my_parameter = n then set B to item_num set count_type to "B" else if text item 2 of my_parameter = cur then set B to "" set current_type to "B" else if text item 2 of my_parameter = fol then set B to folder_name else if text item 2 of my_parameter ≠ "" then set B to text item 2 of my_parameter else set B to "" end if
if text item 3 of my_parameter = t then set C to current_day else if text item 3 of my_parameter = n then set C to item_num set count_type to "C" else if text item 3 of my_parameter = cur then set C to "" set current_type to "C" else if text item 3 of my_parameter = fol then set C to folder_name else if text item 3 of my_parameter ≠ "" then set C to text item 3 of my_parameter else set C to "" end if set AppleScript's text item delimiters to oldDelim
tell application "Finder" set g_i to 0 --遊びで使ってます、よかったらエラー処理に役立たせてください repeat with select_item in (selection as list) set file_path to select_item as text set g_i to g_i + 1 if file_path contains "." then --ファイルのとき(拡張子の有無を判定。二重拡張子、親フォルダに"."がある場合は成り立たない理由) set oldDelim to AppleScript's text item delimiters set AppleScript's text item delimiters to "." set item_ext to last text item of file_path --拡張子取得 set current_name_text to text item 1 of file_path
try set AppleScript's text item delimiters to ":" set current_name_list to "" repeat with ii from 1 to (count text item of current_name_text) set list_demo to text item ii of current_name_text set current_name_list to current_name_list & list_demo as list end repeat end try set current_name to last text item of current_name_list --現在の名前取得 set AppleScript's text item delimiters to oldDelim
--変数になるcurとnはrepeat内 --引数にcurがあったとき if current_type = "A" then set A to current_name else if current_type = "B" then set B to current_name else if current_type = "C" then set C to current_name end if
--引数にnがあったとき if count_type = "A" then set A to my count_up(A) else if count_type = "B" then set B to my count_up(B) else if count_type = "C" then set C to my count_up(C) end if
--リネーム if C = "" and B = "" then set name of select_item to A & "." & item_ext as Unicode text else if C = "" then set name of select_item to A & separator & B & "." & item_ext as Unicode text else set name of select_item to A & separator & B & separator & C & "." & item_ext as Unicode text end if else --フォルダのとき try set AppleScript's text item delimiters to ":" set current_name_list to "" repeat with ii from 1 to (count text item of file_path) set list_demo to text item ii of file_path set current_name_list to current_name_list & list_demo as list end repeat end try set current_name to last text item of current_name_list --現在の名前取得 set AppleScript's text item delimiters to oldDelim
--変数になるcurとnはrepeat内 --引数にcurがあったとき if current_type = "A" then set A to current_name else if current_type = "B" then set B to current_name else if current_type = "C" then set C to current_name end if
--引数にnがあったとき if count_type = "A" then set A to my count_up(A) else if count_type = "B" then set B to my count_up(B) else if count_type = "C" then set C to my count_up(C) end if
--リネーム if C = "" and B = "" then set name of select_item to A as Unicode text else if C = "" then set name of select_item to A & separator & B as Unicode text else set name of select_item to A & separator & B & separator & C as Unicode text end if end if end repeat end tell if growl_run = "true" then set g_i to "total " & g_i & " items" as text my growlRegister() growlNotify("End Run Rename", g_i) end if end alfred_script
--サブルーチン --カウントアップ -- 一桁にする・・・[2],[3]をコメントアウト -- 二桁にする・・・[3]をコメントアウト -- 三桁にする・・・[2]をコメントアウト -- (コメントアウトは行頭に"--"をつけてください) to count_up(type) set type to type + 1 -- [1] --set type to text -2 thru -1 of ("0" & type) -- [2] set type to text -3 thru -1 of ("00" & type) -- [3] return type end count_up
--Growlサブルーチン --エラーの方は使ってません。よかったらどこかに設置してください。 using terms from application "GrowlHelperApp" on growlRegister() tell application "GrowlHelperApp" register as application "Light Renamer" all notifications {"Notification"} default notifications {"Notification"} icon of application "Alfred.app" end tell end growlRegister on growlRegister_error() tell application "GrowlHelperApp" register as application "Light Renamer error" all notifications {"Alert"} default notifications {"Alert"} icon of application "Alfred.app" end tell end growlRegister_error on growlNotify(grrTitle, grrDescription) tell application "GrowlHelperApp" notify with name "Notification" title grrTitle description grrDescription application name "Light Renamer" end tell end growlNotify on growlNotify_error(grrTitle, grrDescription) tell application "GrowlHelperApp" notify with name "Alert" title grrTitle description grrDescription application name "Light Renamer error" end tell end growlNotify_error end using terms from
on rename(new_name) tell application "Finder" repeat with select_item in (selection as list) set file_path to select_item as text if file_path contains "." then --ファイルのとき set oldDelim to AppleScript's text item delimiters set AppleScript's text item delimiters to "." --二重拡張子は無視 set item_ext to text item 2 of file_path set AppleScript's text item delimiters to oldDelim set name of select_item to new_name & "." & item_ext delay 0.05 --タマに重複することがある(うちだけ?) else --フォルダのとき set name of select_item to new_name delay 0.05 --タマに重複することがある(うちだけ?) end if end repeat end tell end rename