set breed_all to every breed of pig set tempValue to 0
repeat with theBreed in breed_all set theUmami to (umami of (toro of theBreed)) as number if theUmami >= tempValue then -- set tempValue to theUmami set niku_best to name of theBreed end if end repeat
昨日違うスレで、フォルダの中の変更日より一ヶ月以上経過しているファイルを削除するスクリプトを教えていただきましたが、フォルダの中の一番上層の階層に対しては機能するのですが2番目以降の階層に対しては機能しません。 いろいろ書き換えて試したのですが、うまくいきません。どのように書き直すとうまくいくのでしょうか、勉強不足で申し訳ありませんが教えてください。 昨日教えていただいたところまでのスクリプトは以下です。 on open d_items del_old(d_items) end open
on del_old(d_items) tell application "Finder" repeat with a_file in d_items if folder (a_file as string) exists then set sub_items to every item of folder (a_file as string) my del_old(sub_items) else set cr_date to current date set md_date to (modification date of a_file) if (year of md_date) < (year of cr_date) then move a_file to trash else if (month of md_date) < ((month of cr_date) - 1) then move a_file to trash else if (month of md_date) < (month of cr_date) and (date of md_date) < (date of cr_date) then move a_file to trash end if end if end repeat end tell end del_old
>>351 >if (year of md_date) < (year of cr_date) then >move a_file to trash だと年が変わってる場合は一ヶ月経ってなくてもゴミ箱行ってしまう気がする
353 名前:351 [2006/01/19(木) 18:37:25 ID:IzKt/HwI0]
352さん、 if (year of md_date) < ((year of cr_date) - 1) then move a_file to trash else if (year of md_date) = ((year of cr_date) - 1) and ((month of md_date) - 12) < (month of cr_date) then move a_file to trash なら年が変わっても大丈夫?
if (year of md_date) < ((year of cr_date) - 1) then move a_file to trash else if (year of md_date) = ((year of cr_date) - 1) and ((month of md_date) - 11) < (month of cr_date) then move a_file to trash else if (year of md_date) = ((year of cr_date) - 1) and ((month of md_date) - 11) = (month of cr_date) and (day of md_date) < (day of cr_date) then move a_file to trash こうしないとだめですね。
一ヶ月以上という設定は if (year of md_date) < ((year of cr_date) - 1) then move a_file to trash else if (year of md_date) = ((year of cr_date) - 1) and ((month of md_date) - 11) < (month of cr_date) then move a_file to trash else if (year of md_date) = ((year of cr_date) - 1) and ((month of md_date) - 11) = (month of cr_date) and (day of md_date) < (day of cr_date) then move a_file to trash else if (year of md_date) = (year of cr_date) and (month of md_date) < ((month of cr_date) - 1) then move a_file to trash else if (year of md_date) = (year of cr_date) and (month of md_date) = ((month of cr_date) - 1) and (date of md_date) < (date of cr_date) then move a_file to trash ここまでしないとだめですかね?
set md_date to (modification date of a_file) set check_date to (current date) - 60 * 60 * 24 * 30 if check_date > md_date then --move a_file to trash display alert ("delete" & return & a_file as string) end if こうかな。
on open theItemList tell application "Finder" my moveToTrash(theItemList) end tell end open
on moveToTrash(theItemList) tell application "Finder" set theFileList to every file of theItemList repeat with theFile in theFileList if ((current date) - (modification date of theFile)) > days * 30 then move theFile to trash end if end repeat my moveToTrash((every folder of theItemList)) end tell end moveToTrash
on open d_items del_old(d_items) end open on del_old(d_items) repeat with a_file in d_items set theInfo to info for a_file without size if folder of theInfo then tell application "Finder" set checkFiles to entire contents of folder (a_file as string) end tell else tell application "Finder" set checkFiles to {file (a_file as string)} end tell end if tell application "Finder" repeat with a_file in checkFiles if folder is not class of a_file then set md_date to (modification date of a_file) set check_date to (current date) - days * 30 if check_date > md_date then --move a_file to trash display alert ("delete" & return & a_file as string) end if end if end repeat end tell end repeat end del_old 359のが短くていいけど普通に書いてみた。 daysなんて定数あるんだね。知らんかった
>>360 あー、my moveToTrash((every folder of theItemList)) の部分は set theFolderList to every folder of theItemList repeat with theFolder in theFolderList my moveToTrash(theFolder) end repeat にしないと無限ループに陥ってしまうわ。
自動的に、言語環境をドイツ語に変えてくれるスクリプトを作りたくて tell application "System Events" tell application process "System Preferences" click radio button "言語" of tab group 1 of window "言語環境" click pop up button 1 of tab group 1 of window "言語環境" pick menu item "ドイツ語" of menu of pop up button 1 of tab group 1 of window "言語環境" end tell end tell tell application "System Preferences" to quit としてみたのですがこれだと並べ替えリストの順序をかえるだけで だめなのです。。 環境設定の言語環境の言語順の順番をscriptで入れ替えることはできないのでしょうか?
on run return end run on idle return 536870909 end idle on quit tell application "Finder" set itemsAlias to every item of (folder "ログアウト項目" of folder (path to library folder from user domain)) if (count of itemsAlias) is greater than 0 then try display dialog "ログアウト項目があります" & return & return & "3秒後に開きます" buttons {"キャンセル", "開く"} default button 1 with icon stop giving up after 3 open itemsAlias end try end if end tell continue quit end quit
--ディスプレイスリープまでの時間を1分に変更。最後に設定を元に戻す。 set curDRW to paragraph 1 of (do shell script "pmset -g ps")
tell application "Finder" set plistFile to file "com.apple.PowerManagement.plist" of folder "SystemConfiguration" of folder "Preferences" of (path to library folder) set plistFile to plistFile as string end tell
tell application "System Events" if curDRW ends with "AC Power'" then set displaySleepTimer to (|Display Sleep Timer| of |AC Power| of ((value of property list item "Custom Profile" of property list file plistFile) as record)) as integer --↑ここをdefauts readで取得する方法はないですか? set curOpt to "c" doPMSet(displaySleepTimer, curOpt) of me else if curDRW ends with "Battery Power'" then set displaySleepTimer to (|Display Sleep Timer| of |Battery Power| of ((value of property list item "Custom Profile" of property list file plistFile) as record)) as integer set curOpt to "b" doPMSet(displaySleepTimer, curOpt) of me else return end if end tell
on doPMSet(theTime, theOption) do shell script "sudo pmset -" & theOption & " displaysleep 1" user name (do shell script "whoami") password "[管理者パスワード]" with administrator privileges delay 63 --1分3秒待って元の設定に戻す。 do shell script "sudo pmset -" & theOption & " displaysleep " & theTime user name (do shell script "whoami") password "[管理者パスワード]" with administrator privileges end doPMSet
do shell script ("pmset dim 1") password "your_password" ¬ with administrator privileges delay 90 do shell script ("pmset dim 30") password "your_password" ¬ with administrator privileges
tell application "System Preferences" activate set current pane to pane "com.apple.preference.displays" end tell tell application "System Events" tell process "System Preferences" tell tab group 1 of window 1 click radio button "Display" tell table 1 of scroll area 1 of group 1 select row 9 -- modify this value end tell end tell end tell end tell tell application "System Preferences" to quit
(1) Finderより取得(10.4のみ動作可能) tell application "Finder" to bounds of the window of the desktop 命令的には、Finderの背景としてあるデスクトップをウインドウとして見て、 そのウインドウの大きさを取得しているらしい。 返り値はFinderと同じ意味の数値のリストらしく、1024x768なら、{0,0,1024,768}となる。 たぶん、432にとっては一番簡単な方法。
tell application "System Events" tell process "SystemUIServer" tell first menu bar set menuExtraList to every menu bar item repeat with aExtra in menuExtraList try tell aExtra click try tell front menu tell menu item "ログインウインドウ..." to click return 0 end tell on error click end try end tell end try end repeat end tell end tell beep end tell
ウソ情報を出してしまった441です。 >>444のを試してみたのだが…4番目のevery menu bar itemでエラーに。 バックグラウンドのアプリケーションのメニューを引っ張り出すっていう方法は すごく参考になったけども、SystemUIServerでevery menu bar の取得が出来てない模様。 (Prove Menu Bar.applescriptのtell processに、"SystemUIServer"を指定して確認) これ、OSのバージョンの問題かな。10.3.9だからダメなのかも。 >>444が動いた方、環境をぜひ教えて下さいな。
set a to text returned of (display dialog "半角数字でも全角数字でも" default answer "") set b to "" repeat with x in (text items of a) if x contains "0" or x contains 0 then set b to b & "0" if x contains "1" or x contains 1 then set b to b & "1" if x contains "2" or x contains 2 then set b to b & "2" if x contains "3" or x contains 3 then set b to b & "3" if x contains "4" or x contains 4 then set b to b & "4" if x contains "5" or x contains 5 then set b to b & "5" if x contains "6" or x contains 6 then set b to b & "6" if x contains "7" or x contains 7 then set b to b & "7" if x contains "8" or x contains 8 then set b to b & "8" if x contains "9" or x contains 9 then set b to b & "9" if x contains "−" or x contains "-" then set b to b & "-" if x contains "." or x contains "." then set b to b & "." end repeat set a to b as number
ファストユーザースイッチを自動で切り替えてかつ、切り替え時に safariを常時あげてくれるスクリプトをがんばって書いてます。 set h to do shell script "whoami" set newUser to "hogehoge1" set userName to "hogehoge" set newUser to do shell script "id -u " & userName do shell script "/System/Library/CoreServices/Menu\\ Extras/User.menu/Contents/Resources/CGSession -switchToUserID " & newUser do shell script "/System/Library/CoreServices/Menu\\ Extras/User.menu/Contents/Resources/CGSession -suspend"
property temp : "" on idle tell application "iTunes" tell current track set newtemp to (artist as string) & ". " & (name as string) set tempgenre to genre end tell end tell if newtemp is not equal to temp then if tempgenre is in {"Drum & Bass", "Drum'n'Bass", "Electronic", "Electronica/Dance", "House"} then set tempvoice to "Zarvox" else set tempvoice to "Vicki" end if tell application "iTunes" repeat with i from 0 to 8 set sound volume to sound volume - i delay 0.1 end repeat end tell say newtemp using tempvoice set temp to newtemp tell application "iTunes" repeat with i from 0 to 8 set sound volume to sound volume + i delay 0.1 end repeat end tell end if return 4 end idle
if ((creator type) of obj is "TVOD") or ((file type) of obj is "dvc!" or "MooV") tell application "QuickTime Player" activate set high quality of track "ビデオ トラック" of movie 1 of window 1 to true end tell end if
tell application "QuickTime Player" tell movie 1 set dimensions to {640, 480} set high quality of tracks to true set deinterlace fields of tracks to true end tell end tell
Safariでやってみた tell application "Safari" make new document with properties {URL:"checkip.dyndns.org/"} set theWin to id of window 1 delay 2--ロード待ち(手抜き) set myIP to word 4 of text of document of window id theWin close window id theWin end tell
tell application "Safari" open location "phobos.apple.com/WebObjects/MZStore.woa/wa/com.apple.jingle.app.store.DirectAction/viewTopSongs/" delay 5 end tell say "Welcome to iTunesMusicStore Japan today's top 100." delay 0.5 say "Okay, now let's start to count down the top 100 songs." tell application "iTunes" repeat with i from 100 to 1 by -1 say "today's number" & i set (sound volume) to 80 play repeat until (player position ? 27) delay 1 end repeat if (i > 1) then set (sound volume) to 50 say "okay, Let's go to the next tune." pause next track end if end repeat end tell
on run tell application "iTunes" set theTrack to item 1 of selection if lyrics of theTrack is "" then beep return end if OpenQtp(location of theTrack, lyrics of theTrack) of me end tell end run
on OpenQtp(theFile, theLyrics) tell application "QuickTime Player" activate open theFile --歌詞埋め込み set the clipboard to theLyrics as string select all movie 1 add movie 1 with scaled set dimensions of last track of movie 1 to {320, 240} set position of last track of movie 1 to {0, 0} --TextFrame更新 set scroll of frames of last track of movie 1 to {scroll in, scroll continuous} --後処理 select none movie 1 rewind movie 1 start movie 1 end tell end OpenQtp
>>560 tell application "System Preferences" activate reveal anchor 1 of pane id "com.apple.preference.startupdisk" --reveal anchor 1 of pane "起動ディスク" end tell
tell application "System Events" tell process "System Preferences" repeat until (exists button "Mac OS J1-9.2.2 (Macintosh HD 上)" of radio group 1 of scroll area 1 of group 1 of splitter group 1 of window 1) delay 1 end repeat click button "Mac OS J1-9.2.2 (Macintosh HD 上)" of radio group 1 of scroll area 1 of group 1 of splitter group 1 of window 1 delay 1 click button 6 of window 1 -- click button "再起動..." of window 1 repeat until (exists sheet 1 of window 1) delay 1 end repeat keystroke return end tell end tell
ボタンをクリックしてシステムを選択する部分だけどうしても言語環境に依存せざるを得ませんでした。 OS 9が必ず「button 2」になると決まっていればできなくもないけど。
click item 1 of (every button whose name contains "9.2") of radio group 1 of scroll area 1 of group 1 of splitter group 1 of window 1
set theSource to choose folder with prompt "Source:" set theDestination to choose folder with prompt "Destination:" tell application "Finder" to set theFiles to every file of folder theSource whose name ends with ".txt" repeat with aFile in theFiles set newName to do shell script "echo " & name of aFile & " | sed 's/\\.txt/.rtf/'" tell application "Finder" set newFile to (make new file at folder theDestination with properties {name:newName}) as string open aFile end tell tell application "TextEdit" activate tell application "System Events" keystroke "t" using {command down, shift down} end tell save front document in newFile as alias close front document end tell end repeat
特定のフォルダーからファイル名のリストを取得するスクリプトなんですが、 OS10.3から10.4にバージョンを上げたところ リストがおかしくなってしまいました。 10.3の時は「10001.jpg」 10.4では「1 0 0 0 1 . jpg」 となってしまいます。何が原因か全く検討がつきません。 どなたか、原因の解る方がおられましたらアドバイスいただけないでしょうか。 宜しくお願いします。 copy cell "basepath" of current record to theBasePath set aPath to theBasePath as string set aFolderA to (aPath & "gazou:") as alias set aContA to "" as text tell application "Finder" try move file (aPath & "list_full.txt") to trash end try set aListA to (every file of aFolderA) repeat with aFile in aListA set My_Name to name of aFile set aContA to (aContA & My_Name & return) end repeat try set fileNum to open for access file (aPath & "list_full.txt") with write permission write (aContA) to fileNum close access fileNum end try end tell
このスクリプトで問題無く書く出せるのですが、 シェルでシンプルにしようと書き出し部分を下記2行のような方法で 行えると思ったんですが、上手く行きません。何がいけないんでしょうか。 どなたかご教授ねがえたらアドバイス願いします。 set A to B do shell script "cd ~/desktop; echo " & A & " > a.txt" ------------------------------------------------------------------- set A to readSomeLines(choose file of "", 50) set aPath to "Macintosh HD:Users:Shared:testdb:" try move file (aPath & "list.txt") to trash end try try delete file (aPath & "list.txt") end try try set fileNum to open for access file (aPath & "list.txt") with write permission write (A) to fileNum close access fileNum end try
on readSomeLines(theFile, theLine) set textData to "" try open for access theFile repeat theLine times set textData to textData & (read theFile until return) end repeat end try close access theFile return textData end readSomeLines
--Finderで選択中の物の中で.mp3で名前が終わるファイルの --クリエータとファイルタイプを変更するスクリプト tell application "Finder" repeat with aFile in (every file of selection whose name ends with ".mp3") set creator type of aFile to "TVOD" set file type of aFile to "MPEG" end repeat end tell
結局、10.4.6/AppleScript 1.10.6/スクリプトエディタ 2.1.1の環境では、 下記のような物しか動かないみたいだな。 tell application "Finder" repeat with aFile in (selection as list) if name of aFile ends with ".mp3" then set creator type of aFile to "hook" set file type of aFile to "MPG3" end if end repeat end tell
レス違いだったら申し訳有りません。 ファイルメーカー用に使用するスクリプととし用意した物なんですが、 (read theFile until return)の部分を受け付けてくれません。 何故受け付けてくれないのかが解りません。 スクリプトエディタ上では問題無く動くんですが・・・。 詳しい方、アドバイスいただけないでしょうか。宜しくお願いします。
set A to readSomeLines(choose file of "", 200)
on readSomeLines(theFile, theLine) set textData to "" try open for access theFile repeat theLine times set textData to textData & (read theFile until return) end repeat end try close access theFile return textData end readSomeLines
>>619 アドバイスを基に修正したのですが、更に上手く行かない箇所があります。 set A to readSomeLines(theBasePath of "", 200) なんですが、set A to readSomeLines(choose file of "", 200)を基に 別途取得したパスを使って指定のファイルから読み込みしたいのですが、 何が足りないんでしょうか。 へたれですみませんが、アドバイスお願いします。
copy cell "path" of current record to theBasePath
set A to readSomeLines(theBasePath of "", 200) do shell script "cd ~/desktop/imageget/script; echo " & quoted form of A & " > C.txt"
on readSomeLines(theFile, theLine) tell application "Finder" set textData to "" try open for access theFile repeat theLine times set textData to textData & (read theFile until return) end repeat end try close access theFile return textData end tell end readSomeLines
628です。URL Access Scriptingだと進行状況がわからない&キャンセルできないので ターミナルでcurl使ってダウンロードすることにしました。 保存するファイル名を指定できるAppleScript対応ダウンローダーってありますかね。 YouTubeからファイル名をタイトルにしてムービフォルダに動画を保存するスクリプト。 日本語ファイル名は試してない。 tell application "Safari" set theURL to URL of document 1 set theTitle to name of document 1 set theTitle to text 11 thru -1 of theTitle end tell if theURL starts with "www.youtube.com/watch?v=" then --動画表示ページからURLを抜き出す set theFLVURL to do shell script "curl --max-time 30 " & quoted form of theURL & " | perl -e '$data = join(q||,<>); ($tmp, $key) = split( q{player.swf?}, $data ); ($key) = split( q{\"},$key ); print qq{www.youtube.com/get_video$key}; '" --保存フォルダ tell application "Finder" set theFolder to (home as string) & "Movies:" set theSavePath to theFolder & theTitle & ".flv" set isExist to exists (file theSavePath) end tell if isExist then say "already exists " & theTitle else tell application "Terminal" do script "curl -L -o " & quoted form of POSIX path of theSavePath & " " & quoted form of theFLVURL & "; say finish download" end tell end if end if
--Finder 上でアプレットを選択して実行 tell application "Finder" activate set applets to {} set appNames to "" repeat with j in (selection as list) tell application "System Events" set pkBool to package folder of (j as alias) set creatorType to creator type of (j as alias) end tell if (pkBool is true) and (creatorType is "aplt") and (exists folder "Japanese.lproj" of folder "Resources" of folder "Contents" of (j as alias)) is false then set applets to applets & (j as alias) set appNames to appNames & (name of (j as alias)) & return end if end repeat if not applets is {} then display dialog appNames & return & "に Japanese.lproj を追加します。" repeat with jj in applets make new folder at folder "Resources" of folder "Contents" of (jj as alias) with properties {name:"Japanese.lproj"} end repeat display dialog "完了" buttons {"OK"} default button 1 giving up after 1 else display dialog "Japanese.lproj を追加する必要がないようです。" buttons {"キャンセル"} default button 1 giving up after 2 end if end tell
if (pkBool is true) and ((creatorType is "aplt") or (creatorType is "dplt")) and (exists folder "Japanese.lproj" of folder "Resources" of folder "Contents" of (j as alias)) is false then
class curlのカッコが凄い事になってるな。 それを避けて扱いやすくする方法がある。 下記の場合、コンパイルする時に、その環境にiCabがインストールされている事が必要。
tell application "Firefox" using terms from application "iCab" set urlStr to URL of window 1 end using terms from end tell set htmlStr to do shell script "curl -s " & urlStr
set aPath to (theBasePath & "Image:General:") as string set aFolderA to POSIX path of ((aPath & "photo:") as alias) set aFolderB to POSIX path of (aPath as alias) set aContA to "" as text set aContA to do shell script "ls -v "& aFolderA &" > "& aFolderB &"/list.txt" end tell
--//ゴミ箱の内容を取得 tell application "Finder" set |項目リスト| to (every item of trash) set |項目テキスト| to ("" as Unicode text) repeat with |項目| in |項目リスト| set |項目テキスト| to |項目テキスト| & return & (POSIX path of (|項目| as alias)) as Unicode text end repeat end tell --//空なら終了 if |項目テキスト| is equal to ("" as Unicode text) then display alert "ゴミ箱は空です" message "" as informational buttons {"終了"} default button 1 giving up after 3 return 0 end if
--//処理を選択させる try display alert "ゴミ箱を空にします!!" message "ゴミ箱の内容:" & (|項目テキスト| as string) as critical buttons {"しない", "ゴミ箱を開く", "OK"} cancel button 1 default button 3 set |選択処理| to (button returned of result) on error return 0 end try --//選択に合わせて処理 if |選択処理| is equal to "OK" then --//ゴミ箱の内容を削除 set |パスリスト| to every paragraph of |項目テキスト| repeat with |パス| in |パスリスト| if (|パス| as Unicode text) is not equal to ("" as Unicode text) then do shell script "rm -rf '" & |パス| & "'" end if end repeat else --//ゴミ箱を開く tell application "Finder" open trash end tell end if
>>753 --最後に再生した日を変更 tell application "iTunes" set seltrack to a reference to selection repeat with x in seltrack set pldate to ((played date) of x as string) if pldate is "missing value" then set pldate to (current date) as string set newdate to text returned of (display dialog "最後に再生した日を変更" default answer pldate) set (played date) of x to date newdate end repeat end tell
activate application "iChat" tell application "System Events" tell process "iChat" try set tbl to table 1 of scroll area 1 of window 1 set tblRow to row of tbl set num to number of tblRow display dialog num & "人" end try end tell end tell
-- 検索ワードに1~5を入力 repeat with i from 1 to 5 do JavaScript "document.f.q.value = " & i & ";" in document 1 delay 1 end repeat
--ウェブ全体から検索 日本語のページを検索のトグル do JavaScript "document.f.lr[1].checked = true;" in document 1 delay 1 do JavaScript "document.f.lr[0].checked = true;" in document 1 delay 1 do JavaScript "document.f.lr[1].checked = true;" in document 1
--検索実行 do JavaScript "document.f.submit();" in document 1 end tell
(* sdefMerge.applescript *) -- 1/2 set suiteTags to {} set suiteObjects to {}
do shell script "ls /tmp/*.sdef" repeat with sdef in paragraphs of the result
set FH to open for access (sdef as POSIX file) set x to read FH using delimiter "<" close access FH
set {theSuite, inDepth} to {"", 0} repeat with i in x if inDepth < 2 then if i begins with "suite" then if (i as text) is not in suiteTags then set theSuite to theSuite & "<" & i as text set end of suiteTags to i as text set inDepth to 2 else set inDepth to 3 end if end if
-- 2/2 else if inDepth = 2 then if i begins with "/suite" then set theSuite to theSuite & "<" & i as text set end of suiteObjects to theSuite set theSuite to "" set inDepth to 1 else set theSuite to theSuite & "<" & i as text end if else if inDepth = 3 then if i begins with "/suite" then set inDepth to 1 end if end repeat -- with i
end repeat -- with sdef
-- set line1 to "<?xml version=¥"1.0¥" encoding=¥"UTF-8¥"?>" set line2 to "<!DOCTYPE dictionary SYSTEM ¥"file://localhost/System/Library/DTDs/sdef.dtd¥">"
set outputFileRef to (choose file name default name "Various Suites.sdef" default location (path to desktop folder))
set AppleScript's text item delimiters to return set suiteObjects to suiteObjects as text set AppleScript's text item delimiters to ""
set FH to open for access outputFileRef with write permission write line1 & return & line2 & return & "<dictionary>" & suiteObjects & "</dictionary>" to FH close access FH
tell application "Script Editor" to open outputFileRef
昔再生してる曲のアートワークをDragThingのゴミ箱アイコンにしてたので それをちょっと改造してみた。別途osaxが必要です。 --iTunesで再生してる曲のアートワークをデスクトップピクチャにする --必要なosax GraphicsImporter OSAX --www.azug.gr.jp/~h-abe/freeware/gio/index.ja.html tell application "iTunes" set theCurrentTrack to current track try set theArtwork to data of artwork 1 of theCurrentTrack on error error_message return -1 end try end tell -- iTunes7で取得したアートワークは形式不明で変換しないと駄目みたいだった -- 昔埋め込んだのはpictで取り出せるけどpictはデスクトップに貼れないみたい try set theArtwork to giconvert theArtwork type "JPEG" --resolution {72, 72} on error error_message return -1 end try set theFolder to path to desktop as string set theHFSFile to theFolder & "iTunes_Artwork_to_Desktop.pict" set refNum to open for access theHFSFile with write permission if refNum > 0 then write theArtwork to refNum close access refNum else return -1 --アートワークを保存できなかったので終了 end if tell application "Finder"--PICT、TIFFは設定できないみたい set desktop picture to theHFSFile as alias end tell
set {y, m, d, w, h, min, sec} to my date2list((current date)) if h < 6 then display dialog "The date has been changed already." & return & "Do you want to overwrite the date as it is still on the previous date?" buttons {"No", "Yes"} default button 2 giving up after 15 if button returned of result is not equal to "No" then set {y, m, d, w, h, min, sec} to my date2list((current date) - h * hours - min * minutes - sec - 60) end if
set wkd to item w of {" (Sun)", " (Mon)", " (Tue)", " (Wed)", " (Thu)", " (Fri)", " (Sat)"} set sdate to "" & y & "-" & m & "-" & d & wkd
sdate
on date2list(aDate) if class of aDate = date then set theDate to aDate else set theDate to current date end if tell theDate to return {year, its month as number, day, its weekday as number, its hours, its minutes, its seconds} end date2list
tell application "System Events" tell application process "Preview" tell application "Preview" to activate delay 0.5 keystroke "n" using command down delay 0.5 end tell end tell
tell application "iTunes" set seltrack to a reference to selection set theartwork to data of artwork 1 of item 1 of seltrack set the clipboard to theartwork end tell
tell application "System Events" tell application process "Preview" tell application "Preview" to activate delay 0.5 keystroke "n" using command down end tell end tell
tell application "System Events" tell application "Preview" to activate repeat if (visible of process "Preview") is true then exit repeat end repeat tell application process "Preview" delay 1 keystroke "n" using command down delay 1 end tell end tell
set current_track to item 1 of selection set artworkData to data of artwork 1 of current_track set imageFormat to format of artwork 1 of current_track as string
-- 画像フォーマットを判定 if imageFormat contains "JPEG" then set extension to ".jpg" else if imageFormat contains "PNG" then set extension to ".png" else return end if
-- ファイル名を設定 set art to artist of current track set alb to album of current track set file_name to (art & " - " & alb & " Artwork" & extension) as string
-- ファイル名に問題あるキャラクターを除去 if file_name contains "/" or file_name contains ":" then repeat with c from 1 to length of (file_name as string) if item c of file_name = "/" or item c of file_name = ":" then set file_name to (text 1 through (c - 1) of file_name) & "_" & (text (c + 1) through length of file_name) end if end repeat end if
-- tmp にアートワークデータを書き出し set tempFile to ("tmp:" & "Artwork.bin" as string) set fileRef to open for access tempFile with write permission write artworkData to fileRef close access fileRef
-- アートワークデータから先頭222バイトを削りデスクトップに保存 do shell script "cd ~/desktop/ ; tail -c +223 " & quoted form of the (POSIX path of tempFile) & " > " & quoted form of (file_name)
>>843 複数の選択を可能にしたければ、 set seltrack to a reference to selection repeat with x in seltrack set artworkData to data of artwork 1 of x 以下同様に処理 end repeat
保存先の指定は、set savefolder to POSIX path of (choose folder) とでもする。
禁止文字の変換はこうすると文は短いが、、、 do shell script "echo " & quoted form of thename & " | sed s/'¥¥/'/_/g | sed s/'¥¥:'/_/g"
tmpを使わぬ処理は tell application "Finder" to set thefile to make new file at thepath with properties {name:ファイル名} set thefile to thefile as alias という風に、先に空のファイルを作ってから、 そこにopen for access〜のようにデータを書き込み、頭222Bを削る。
tell application "iTunes" set extension to ".jpg" set current_track to current track set track_loc to location of current_track end tell
tell application "Finder" set alb to name of (container of track_loc) set art to name of (container of (container of track_loc)) set file_name to (art & " - " & alb & " Artwork" & extension) as Unicode text end tell
set theDate to do shell script "date +%Y-%m-%d¥¥ ¥¥(%a¥¥)" set hr to (do shell script "date +%H") as number if hr < 6 then set theDate to (do shell script "date -r $(($(date +%s)-86400)) +%Y-%m-%d¥¥ ¥¥(%a¥¥)") end if theDate
-- "~/Library/Script/Load Script….scpt" property script_lib_location : (path to library folder from user domain as string) & "Application Support:Script Menu:"
(* On Run *)
tell application "Finder" set scriptsList to displayed name of files of alias script_lib_location set chosenFile to file (script_lib_location & (item 1 of my chooseFromBigList(scriptsList, 10, 1))) if name extension of chosenFile is not equal to "scpt" then return (open chosenFile) end tell
on chooseFromBigList(aList, itemsPerPage, startPage) set nextPageLabel to "[ Next page ] >>" set firstPagelabel to "[ First page ] >>" set totalItems to the length of aList set pageItems to itemsPerPage as integer set pagingOption to nextPageLabel
-- handling some likely errors... if totalItems < pageItems then return (choose from list aList) --with multiple selections allowed) if startPage > (totalItems div pageItems + 1) then error "Invalid argument: startpage=" & startPage end if
set topItemIdx to (startPage - 1) * pageItems + 1
if totalItems < (topItemIdx + pageItems) then -- here we've reached at the last page. set pagingOption to firstPagelabel if not totalItems = (topItemIdx + pageItems - 1) then set pageItems to totalItems mod pageItems end if
set theList to (items topItemIdx thru lastItemIdx of aList) & pagingOption
choose from list theList with title (topItemIdx & " - " & lastItemIdx & " of " & totalItems & " items" as string) default items {pagingOption} --with multiple selections allowed if the result = false then return false else if the last item of result = nextPageLabel then return my chooseFromBigList(aList, itemsPerPage, (startPage + 1)) else if the last item of result = firstPagelabel then return my chooseFromBigList(aList, itemsPerPage, 1) else return the result end if
--escape of file name set fileName to do shell script "echo " & quoted form of fileName & " | sed -e s/:/\\\\//g"
--make unique file name set myDir to ((path to home folder) as string) & mySave set fileNames to fileName & fileExt set i to 0
repeat while ((fileNames) is in (list folder myDir)) set i to i + 1 set fileNames to fileName & i & fileExt end repeat
--make file tell application "System Events" set theFile to make new file at end of folder myDir with properties {name:fileNames} set thePath to path of theFile end tell
--Internet Shortcut data(it needs to be saved by Shift-JIS & CRLF) set wMsg to "[InternetShortcut]" & (ASCII character 13) & (ASCII character 10) & "URL=" & tarURL & (ASCII character 13) & (ASCII character 10) do shell script "echo " & quoted form of wMsg & " | iconv -f UTF8 -t Shift-JIS > " & quoted form of (POSIX path of thePath)
--set comment tell application "Finder" set theFinderFile to file thePath set comment of theFinderFile to myComment end tell
tell application "Safari" to set aList to {(URL of document 1), (do shell script "echo " & quoted form of ((name of document 1) as Unicode text) & --改行 " | perl -pe 's/(^" & (ASCII character 128) & ".|" & (ASCII character 128) & (ASCII character 128) & "|:)/_/g'")} --改行 tell application "Finder" to (make new internet location file at (folder "BookMark" of (path to documents folder)) to --改行 (item 1 of aList) with properties {name:(item 2 of aList), comment:(text returned of (display dialog "コメントを入れてください" default answer ""))})
>>875 tell application "System Events" to tell process "TextEdit" to tell scroll area 1 of window 1 to set A to value of text area 1 tell application "Terminal" to do script A in window 1
でいいですかね?あんまUI Element使ったスクリプトって好きじゃないんですよ・・・
分かりやすい書き方だと tell application "System Events" tell process "TextEdit" tell scroll area 1 of window 1 set A to value of text area 1 end tell end tell end tell tell application "Terminal" to do script A in window 1
tell application "System Events" tell process "TextEdit" tell text area 1 of scroll area 1 of window 1 set A to value of attribute "AXSelectedText" end tell end tell end tell
tell application "Terminal" do script A in window 1 end tell
tell application "System Events" tell application "TextEdit" to activate tell process "TextEdit" to keystroke "c" using command down tell application "Terminal" to activate tell process "Terminal" keystroke "v" using command down keystroke return end tell end tell
tell application "System Events" tell application "Jedit X" to activate tell process "Jedit X" to keystroke "c" using command down tell application "Terminal" to activate tell process "Terminal" keystroke "v" using command down keystroke return end tell end tell
on adding folder items to open_folder after receiving target_items tell application "Finder" repeat with obj in target_items set name of obj to "*" & name of obj end repeat end tell end adding folder items to
tell application "iTunes" tell current EQ preset if not modifiable then error "The current preset cannot be modified." set preamp to my qroundFloat(preamp) set band 1 to my qroundFloat(band 1) set band 2 to my qroundFloat(band 2) set band 3 to my qroundFloat(band 3) set band 4 to my qroundFloat(band 4) set band 5 to my qroundFloat(band 5) set band 6 to my qroundFloat(band 6) set band 7 to my qroundFloat(band 7) set band 8 to my qroundFloat(band 8) set band 9 to my qroundFloat(band 9) set band 10 to my qroundFloat(band 10) end tell my checkEQLevels() end tell
---- Subroutines ---- on qroundFloat(aFloat) return aFloat div 0.25 * 0.25 end qroundFloat
on checkEQLevels() tell application "iTunes" to tell current EQ preset display dialog "........Preamp level: " & preamp & " dB" & return & " ..32 Hz band level: " & band 1 & " dB" & return & "..64 Hz band level: " & band 2 & " dB" & return & "125 Hz band level: " & band 3 & " dB 250 Hz band level: " & band 4 & " dB" & return & "500 Hz band level: " & band 5 & " dB" & return & "..1 kHz band level: " & band 6 & " dB ..2 kHz band level: " & band 7 & " dB" & return & "..4 kHz band level: " & band 8 & " dB" & return & "..8 kHz band level: " & band 9 & " dB 16 kHz band level: " & band 10 & " dB" buttons {"OK"} with title "iTunes EQ preset - " & its name with icon 1 end tell end checkEQLevels
-- カスタムアイコンがセットされていない限りpropertyのiconはmissing valueなので、 -- 対策... tell application "Finder" tell selection as list if its length < 1 then return 0 open information window of item 1 set infoWindow to name of the result end tell end tell
tell application "System Events" tell window infoWindow of process "Finder" set iconButton to a reference to button 2 of scroll area 1 if not focused of iconButton then click iconButton keystroke "c" using command end tell end tell
tell application "Finder" close window infoWindow end tell
>>928 まず set theList to {} と空のリストを宣言して、 set end of theList to hoge と、なにかを順次格納していく。 -- 検証コード set theList to {} set end of theList to {1, 3, 5} set end of theList to {2, 4, 6} theList
(************************************************************************************* FinderウインドウをOS 9のポップアップウインドウのようにするスクリプト 自動的に終了しないアプリケーションとして保存する事 *************************************************************************************) on run return end run on idle try with timeout of 35791394 seconds tell application "Finder" set |window list| to every Finder window repeat with |Finder window| in |window list| if (frontmost is false) or ((index of |Finder window|) is not 1) then set (collapsed of |Finder window|) to true end if end repeat end tell end timeout end try return 3 end idle on quit continue quit end quit
set values to {} activate application "Preview" tell application "System Events" tell process "preview" repeat with i in windows set values to values & value of attribute "AXDocument" of i end repeat end tell end tell