(* 稼働中の最前面アプリケーションが在るフォルダを開くScript バージョンが複数あると上手く対処できないモノもあります。*) set sentaku_Appli_Path to ((path to frontmost application) as string) as alias --選択したアプリケーション自体のフルパス
tell application "Finder" activate set Curi_FiTyp_Text to {(creator type of sentaku_Appli_Path) as string} open folder (folder of application file id (Curi_FiTyp_Text) as string) end tell
tell application "System Events" to get application file of last application process whose frontmost is true tell application "Finder" to reveal the result
tell application "System Events" set anapp to (path to frontmost application) end tell tell application "Finder" activate reveal anapp reveal anapp --fileのrevealは稀に失敗することがあるので2回やっとく。 end tell
>>31 >2つをくっつけて参照リスト こうかな -- テストデータ設定 set nameList to {"Untitled 0", "Untitled 1", "Untitled 2", "Untitled 3", "Untitled 4"} set dataList to {0, 1, 2, 3, 4}
if (count nameList) < (count dataList) then set itemLen to count nameList else set itemLen to count dataList end if -- まとめる set i to 1 set newList to {} repeat itemLen times set newList to (newList & {{name:item i of nameList, data:item i of dataList}}) as list set i to i + 1 end repeat -- 結果プリント log itemLen log (count newList) repeat with C in newList log "name : " & name of C & tab & "data: " & data of C end repeat
3連続投稿ごめんなさい(メールの返事とかでもいつも脊椎反射で書くなっていわれるけど、治らない) 昨日いろいろやったやつあけてみるとほぼ同じのがあった で、{ を2重にするのがキモなんですね {{name:item i of nameList, data:item i of dataList}} これがわかれば、、、なんか、もう何も怖くないぞって気がしてきた(気のせい気のせい) 重ね重ね本当にありがとうございました
set friendList to {{{name:"はるか", data:"八方美人"}, {name:"まるみ", data:"おっとりタイプ"}, {name:"このデータは削除されました", data:"最悪"}, {name:"なお", data:"可愛い子"}, {name:"てるみ", data:"天然"}}, {{name:"せーじ", data:"マジ死ねば?"}, {name:"ともゆき", data:"ネクラ"}, {name:"くっちゃん", data:"便利なタクシー"}}} log friendList --だれかのタイプを変えてみよう set searchChara to "てるみ" set chengeChara to "やんちゃ" repeat with friendListitem in friendList repeat with friendItem in friendListitem if {name:searchChara} is in friendItem then set data of friendItem to chengeChara end repeat end repeat log friendList
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
--"Macintosh HD:Users:hoge:documents:add:"用のフォルダアクション on adding folder items to this_folder after receiving these_items set theDate to (do shell script "date '+%s'") tell application "Finder" make new alias file at (path to desktop folder) to these_items with properties {comment:theDate} end tell end adding folder items to
--ログイン項目用 on idle set theDate to (do shell script "date \"+%s\"") tell application "Finder" set aliasFileList to (every alias file of (path to desktop folder) whose comment is not "") repeat with curAliasFile in aliasFileList set theComment to (comment of curAliasFile) try if theDate - theComment > 60 then if ((container of original item of curAliasFile) as alias) is alias "Macintosh HD:Users:hoge:Documents:add:" then delete curAliasFile end if end if end try end repeat end tell return 1 end idle
set pushTemp to AppleScript's text item delimiters display dialog pushTemp
set aaa to (path to applications folder) as file specification set aaa to aaa as string set AppleScript's text item delimiters to text item -1 of aaa display dialog AppleScript's text item delimiters display dialog (ASCII number of AppleScript's text item delimiters)
set bbb to (path to home folder) as file specification set bbb to bbb as string set ccc to text item -2 of bbb display dialog ccc
set AppleScript's text item delimiters to ":" display dialog AppleScript's text item delimiters display dialog (ASCII number of AppleScript's text item delimiters)
set ddd to (path to home folder) as file specification set ddd to ddd as string set eee to text item -2 of ddd display dialog eee
set AppleScript's text item delimiters to pushTemp
tell application "Finder" activate display dialog "どうするのよ?" buttons {"ああああ", "いいいい"} default button 2 with icon note if button returned of result = "いいいい" then duplicate file "別フォルダに保管してある環境設定ファイル1のパス" to folder "Preferencesフォルダのパス" with replacing beep else duplicate file "別フォルダに保管してある環境設定ファイル2のパス" to folder "Preferencesフォルダのパス" with replacing beep end if delay 2 tell application "その設定ファイルのアプリ" run quit end tell end tell
-- 対象の1ディレクトリを取得 on target_directory() tell application "Finder"
-- 選択がフォルダ1つならそれ set selection_items to selection if ((count of selection_items) is equal to 1) then set first_item to (item 1 of selection_items) try folder (name of selection_items) of (container of first_item) --フォルダでなければはエラーになる return first_item as alias end try end if
-- 手前のFinderウィンドウの表示フォルダ、またはデスクトップ try set insertion_location to (insertion location) return insertion_location as alias --コンピュータディエレクトリなどはエラーになる end try
end tell error "フォルダが特定できません" end target_directory
>>164 tell application "iTunes" set defaults_message to 0 tell me display dialog "追加するカウント: " default answer defaults_message with icon note set ret to result end tell set v_count to 0
if ((button returned) of ret) = "OK" then set v_count to (text returned) of ret as number else return end if
set t_list to selection of window 1 repeat with tC in t_list copy tC to C if true then -- ここをfalseにすると入力値がそのまま再生回数になる set newCount to v_count + (played count of C) if newCount < 0 then set newCount to 0 set played count of C to newCount else if played count of C is not v_count then set played count of C to v_count end if end if end repeat end tell (* 選択範囲対象。再生回数にマイナス値も設定できるのか。要全角スペース置換 *)
(* 再生日を捏造 数秒のBEEP音数個でしか試していない *) >>165 に追加 set dateTmp to current date -- 追加 repeat with tC in t_list -- (ry -- 日付捏造開始 -- try set timeduration to duration of C set dateTmp to (dateTmp - timeduration) as date set datePlayed to played date of C set dateAdded to date added of C if datePlayed is missing value or dateTmp > dateAdded then set played date of C to dateTmp else if dateAdded is not missing value then set played date of C to dateAdded end if end if -- end try -- 日付捏造終了 end repeat end tell (* 対象リストをひっくり返すか、改造した方がよいかも *)
on open theList repeat with curltem in theList display dialog theList as string end repeat end open
そうするとtheListには, Macintosh HD:Desktop Folder:名称未設定フォルダ:A Macintosh HD:Desktop Folder:名称未設定フォルダ:B Macintosh HD:Desktop Folder:名称未設定フォルダ:C というデータが格納されますよね.
このtheListの中を, Macintosh HD:Desktop Folder:名称未設定フォルダ:A Macintosh HD:Desktop Folder:名称未設定フォルダ:C のかたちにしたいわけです.
>>176 例1) on open theList tell application "Finder" repeat with curltem in theList if name of curltem is not "B" then display dialog curltem as string end if end repeat end tell end open
例2) on open theList set theList2 to {} tell application "Finder" repeat with curltem in theList if name of curltem is not "B" then set end of theList2 to contents of curltem end if end repeat display dialog theList2 as string end tell end open
OS: Mac OS X v10.3.9 ScriptEditor: 2.0(v43.1) AppleScript 1.9.3
この環境で
on open drop_items tell application "Finder" (display dialog "Please Enter the date." default answer "2007/1/1") set TextReply to text returned of the result --(ここに、drop_itemsの作成日や変更日を変更するスクリプトを書くつもり) end tell end open
repeat with an_item in dropitems set a_path to an_item as Unicode text if a_path ends with ":" then set folder_contents to list folder an_item repeat with a_name in folder_contents set end of a_list to a_path&a_name end repeat else set end of a_list to an_item end if end repeat
repeat with an_item in a_list display dialog an_item as Unicode text buttons {"OK"} end repeat
>>191 >on open drop_items >tell application "Finder" >(display dialog "Please Enter the date." default answer "2007/1/1") >set TextReply to text returned of the result >--(ここに、drop_itemsの作成日や変更日を変更するスクリプトを書くつもり) >end tell >end open
>>196さん まさにそうでした。 --(ここに、drop_itemsの作成日や変更日を変更するスクリプトを書くつもり) のところで set TextReply to TextReply & " 0:0:0" とすべきところを set TextReply to TextReply and " 0:0:0" なんてお馬鹿なことやってたので…。
--初心者スレを誘導。スペースを削除して、スクリプトエディタに張り付け。ってこんなことせんでもおーとめーたとかでできるんかな? --さくっとつくったから、エラー処理してない。10.4.9でだけ確認。連休明けは仕事する気にならんな。暇つぶし global folderRef global newFileExtension --10.4.9のapplescliptって property 使えたっけ?覚えさすならつかってくんろ
choose folder "拡張子を変更したいフォルダを選択♪" & return & "中にフォルダあったらいまんとこ無視ね" set folderRef to result
display dialog "変えたい拡張子" default answer "rtf" set newFileExtension to (text returned of result) as string
--on open fileList --ドロップレットも対応したければ中身も考えること、ここ生き返らすだけじゃだめだよ? tell application "Finder" set fileList to every file in folderRef --こことかね repeat with objName in fileList set fileClass to class of objName if fileClass is document file then changeNameFile(objName) of me -- ファイルの場合 else -- 中身がフォルダで処理したいときここハンドルにして再帰使えばよいよ end if end repeat end tell --end open --ハンドラにつづきまーす
--はんどらね on changeNameFile(fileAlias) tell application "Finder" set fileExtension to name extension of fileAlias set fileExtension to fileExtension as string set fileName to name of fileAlias set fileName to characters of fileName set fileName to reverse of fileName set x to "" repeat with oneChara in fileName set x to oneChara & x if x is fileExtension then set x to newFileExtension end repeat set fileNameStr to x as string try set name of fileAlias to fileNameStr --set properties of folderRef to {name extension:newFileExtension} --だめ;;ファイルのぷろぱてぃは、りーどおんり? on error display dialog "アクセス権及びファイル名称を確認してね" & return & "後で" buttons "後で" giving up after 5 return end try end tell end changeNameFile
tell application "Finder" tell front Finder window set windoe_bounds to bounds set (item 4 of windoe_bounds) to (item 2 of windoe_bounds) --高さ0にする set bounds to windoe_bounds end tell end tell
OS X 10.4.9 AS 1.10.7 ・set bounds to windoe_boundsでFinder got an error: Can't set bounds of Finder window 1 to {ホゲホゲ}." OS 9.2.2 AS 1.8.3 ・tell front Finder windowでSyntax Error: Expected class name, etc. but found identifier. ・上記をtell front windowに変えて、set bounds to windoe_boundsでFinder got an error: Invalid size for object
tell application "Finder" tell front Finder window set windoe_bounds to bounds if (toolbar visible) then set (item 4 of windoe_bounds) to (item 2 of windoe_bounds) + 36 --高さ36にする else set (item 4 of windoe_bounds) to (item 2 of windoe_bounds) --高さ0にする end if set bounds to windoe_bounds end tell end tell
>>241 こんなのかな tell application "Preview" activate open file "path:to:file.pdf" end tell tell application "System Events" tell process "Preview" repeat while not (exists window 1) end repeat if not (exists tool bar 1 of window 1) then keystroke "b" using {command down} end if repeat while not (exists tool bar 1 of window 1) end repeat repeat while not (focused of text field 1 of group 1 of tool bar 1 of window 1) keystroke tab end repeat set value of text field 1 of group 1 of tool bar 1 of window 1 to "50" keystroke return end tell end tell
>>242 > Previewは最初からApple Scriptには対応してなさそうでしたが、 GUI Scriptingで強引に、ってだけなんだけどねw 動かした奴をコピペするけど、delay n を適当に挟んだ方が確実かもしれない。
tell application "Preview" activate open "hoge.pdf" end tell tell application "System Events" tell process "Preview" keystroke "g" using {command down, option down} keystroke "50" keystroke return end tell end tell
tell application "Script Editor" set _win to count document if _win is 0 then beep error number -128 end if repeat _win times tell application "System Events" keystroke "k" using command down delay 0.3 keystroke "s" using command down delay 0.3 keystroke "w" using command down delay 0.3 end tell end repeat beep end tell
--フォルダー内にあるファイル名のpageをpに略すスクリプトです。 set olddelim to AppleScript's text item delimiters set afolder to choose folder with prompt "名前を整理したいフォルダを選択" global tmpstr tell application "Finder" repeat with afile in every file of afolder set afilename to name of afile my replace(afilename, "page", "p") set name of afile to tmpstr end repeat end tell set AppleScript's text item delimiters to olddelim
to replace(thetext, orgstr, newstr) set AppleScript's text item delimiters to orgstr set tmplist to every text item of thetext set AppleScript's text item delimiters to newstr set tmpstr to tmplist as Unicode text return tmpstr end replace
確認していないけど、replace のなかの tmpstr が local 変数になっているんじゃないだろうか? global 変数であることを期待しているように見えるけど。
次のようにしたらどうでしょう。
on run set olddelim to AppleScript's text item delimiters set afolder to choose folder with prompt "名前を整理したいフォルダを選択" tell application "Finder" repeat with afile in every file of afolder set afilename to name of afile set name of afile to my replace(afilename, "page", "p") end repeat end tell set AppleScript's text item delimiters to olddelim end run
to replace(thetext, orgstr, newstr) set AppleScript's text item delimiters to orgstr set tmplist to every text item of thetext set AppleScript's text item delimiters to newstr set tmpstr to tmplist as Unicode text return tmpstr end replace
set d1 to date "Friday, March 24, 2006 1:38:39 PM" setSysTime(d1) log "done." return on setSysTime(time) tell application "System Preferences" activate reveal anchor "DateTime" of pane id ¬ "com.apple.preference.datetime" end tell tell application "System Events" tell process "System Preferences" tell UI element 7 of group 1 of tab group 1 of window 1 set value to time end tell click button "Save" of group 1 of tab group 1 of window 1 end tell end tell tell application "System Preferences" to quit end setSysTime
on openハンドラに渡されるのはエイリアスのリストなのですが、 これをFinder itemのリストに変換する簡単な方法はありますでしょうか?
on open theAliasList display dialog (class of item 1 of theAliasList) tell application "Finder" to set theList to every item of theAliasList display dialog (class of item 1 of theList) -- my processThem(theList) end open
ちゃちゃっと書いてみた。 OS 8.6 のときと比べて selection の扱いが変わってて戸惑った・・・。
tell application "Finder" repeat with the_item in selection as list set old_name_char to name of the_item set new_name_char to {} repeat with c in old_name_char if (ASCII number of c) < 127 then set the end of new_name_char to contents of c end repeat set the name of the_item to (new_name_char as string) end repeat end tell
Mac OS X 10.3.9, Microsoft Excel v.Xです。 下のようなスクリプトを実行して、A3...G3, A4...G4, ....に1から100までの数値をセットしようとしたんですけど 上手く動いてくれません。 tell application "Microsoft Excel" set cuurentCell to "A3" set i to 0 repeat set Value of Range cuurentCell to i set cuurentCell to my NextCellOf(cuurentCell) set i to i + 1 if i = 100 then exit repeat end if delay 10 end repeat end tell
on NextCellOf(theCell) set firstChar to theCell's first character set lastChar to (theCell's characters 2 through -1) as string if firstChar is not "G" then set newCell to (ASCII character ((ASCII number firstChar) + 1)) & lastChar else set newCell to "A" & ((lastChar as integer) + 1) end if return newCell end NextCellOf
set firstChar to "A" set offsetNum to 3 set cellObj to {} repeat with i from 0 to 6 set cellObj to cellObj & (ASCII character ((ASCII number firstChar) + i)) end repeat
repeat with currentNum from 1 to 100 --1〜100まで set y to currentNum div (count of cellObj) set x to (currentNum - 1) mod (count of cellObj) + 1 set cellName1 to item x of cellObj set cellName2 to y + offsetNum set cellName to cellName1 & cellName2 as Unicode text
Address of Range "xy"で見たら、列Cが異常なアドレスを示してたからこうしてみたよ。良さげな感じ。
tell application "Microsoft Excel" set cuurentCell to "$A$3" set i to 0 repeat set Value of Range cuurentCell to i set cuurentCell to my NextCellOf(cuurentCell) set i to i + 1 if i = 100 then exit repeat end if --delay 10 end repeat end tell
on NextCellOf(theCell) set firstChar to (theCell's characters 2 through 2) as string set lastChar to (theCell's characters 4 through -1) as string if firstChar is not "G" then set newCell to "$" & (ASCII character ((ASCII number firstChar) + 1)) & "$" & lastChar else set newCell to "$A$" & ((lastChar as integer) + 1) end if return newCell end NextCellOf
tell application "Microsoft Excel" set Value of Range "A1" to 2 set Value of Range "B1" to 2 set Value of Range "D1" to 2 --set Value of Range "C1" to 2 --ここを実行すると,A列全てに2が入る. set Value of Range "D1" to 2 set Value of Range "E1" to 2 set Value of Range "F1" to 2 set Value of Range "G1" to 2 set Value of Range "H1" to 2 set Value of Range "I1" to 2 set Value of Range "J1" to 2 set Value of Range "K1" to 2 set Value of Range "L1" to 2 set Value of Range "M1" to 2 set Value of Range "N1" to 2 set Value of Range "O1" to 2 set Value of Range "P1" to 2 set Value of Range "Q1" to 2 --set Value of Range "R1" to 2 --ここを実行すると,1行全てに2が入る. set Value of Range "S1" to 2 set Value of Range "T1" to 2 set Value of Range "U1" to 2 set Value of Range "V1" to 2 set Value of Range "W1" to 2 set Value of Range "X1" to 2 set Value of Range "Y1" to 2 set Value of Range "Z1" to 2 end tell
on open theItemList tell application "Finder" set theFile to choose file name if theFile is false then return else set theCombined to "'" & (POSIX path of theFile) & "'" end if set theArgs to {} repeat with theItem in theItemList set theArgs to theArgs & ("'" & (POSIX path of theItem) & "'") end repeat set theDelimiter to AppleScript's text item delimiters set AppleScript's text item delimiters to " " set theCommand to "cat " & (theArgs as text) & " > " & theCombined set AppleScript's text item delimiters to theDelimiter do shell script theCommand end tell end open
こういうことだろう。 on open に渡されるファイルは名前順ではなく Finder で選択された順のようだ。
if button returned of result = "off" then do shell script "defaults write com.apple.dashboard mcx-disabled -boolean YES" else do shell script "defaults write com.apple.dashboard mcx-disabled -boolean NO" end if
tell application "Finder" set fileList to selection set fileList to sort fileList by name end tell tell application "QuickTime Player" make new movie repeat with i in fileList open i tell movie 1 select all copy end tell close movie 1 tell movie 1 paste end tell end repeat end tell
tell application "Finder" to activate tell application "System Events" tell process "Finder" click menu button 1 of group 2 of tool bar 1 of window 1 repeat while not (exists UI element 2) end repeat if exists menu item "パッケージの内容を表示" of UI element 2 then click menu item "パッケージの内容を表示" of UI element 2 end if end tell end tell
tell application "Finder" set theItem to (selection as alias) set theName to name of theItem set name of theItem to "temp_000" open theItem set name of theItem to theName end tell
--選択項目の"パッケージの内容を表示"するスクリプト property select_menu_title : "パッケージの内容を表示" tell application "Finder" set selected_items to selection set contains_package to false --画面サイズから最大縦幅ウィンドウサイズを計算 set desktop_bounds to bounds of the window of the desktop set item 2 of desktop_bounds to 44 set item 3 of desktop_bounds to 600 --横幅は600固定 --1項目ずつ処理 repeat with an_item in selected_items if package folder of (info for (an_item as alias)) then --パッケージ以外は無視 set contains_package to true --ツールバー表示新規ウィンドウで選択 tell (make new Finder window) set target to folder of an_item select an_item set toolbar visible to true --ツールバーのアクションメニューを操作 my |パッケージを表示を選択|() close end tell
--パッケージ内表示ウィンドウをお好みの表示に tell front Finder window if toolbar visible then set toolbar visible to false set current view to list view set bounds to desktop_bounds --リスト表示で2階層開いておく tell application "System Events" tell process "Finder" repeat 2 times keystroke "a" using command down --全てを選択 key code 124 --→キーでフォルダを開く delay 0.1 end repeat end tell end tell end tell end if end repeat if not contains_package then error "パッケージを選択していません" end tell
on |パッケージを表示を選択|() tell application "Finder" to activate tell application "System Events" tell process "Finder" tell front window tell front tool bar set group_list to every group repeat with a_group in group_list tell a_group set menu_buttons to every menu button repeat with a_menu_button in menu_buttons tell a_menu_button click --ポップアップがウィンドウに属してない tell application "System Events" tell process "Finder" try
tell UI element 2 --なぜかポップアップしてるメニューはこれ tell menu item select_menu_title click end tell end tell return 0 --成功したので終了 end try end tell end tell -- key code 53 --escキーでメニューを消す end tell end repeat end tell end repeat end tell end tell end tell end tell error "ツールバーのアクションメニューを見つけられませんでした" end |パッケージを表示を選択|
tell application "Finder" set theSelection to selection set thePackages to (packages of container of item 1 of theSelection) as string repeat with theSelectItem in theSelection if (theSelectItem as string) is in thePackages then set theItems to items of theSelectItem make new Finder window repeat with i from 1 to count theItems set target of front window to item i of theItems end repeat end if end repeat end tell
tell application "Finder" activate end tell tell application "System Events" set appName to (name of processes whose frontmost is true) as Unicode text display dialog appName end tell
>>423 OS9ですよね? tell application "Finder" get processes whose frontmost is true set MyFile to result as string end tell tell application MyFile display dialog MyFile end tell ダイアログがそのままfrontアプリで出る様にしただけでほぼそのまんま。 うちのOS9.2.2/Applescript1.8.3ではこれでちゃんとアプリ名出るけど。
仮に名前をactionとして、コメントにファイル特定用の印"ABC"を書き込んでおきます。 tell application "Finder" set MyFile to name of (every file in folder "actionの入ってるフォルダ:" whose comment is "ABC") get processes whose frontmost is true set MyApp to result as string if MyApp is "" then set MyApp to "Finder" end tell tell application MyApp display dialog MyFile end tell
tell application "Finder" set desktopWindow to window of the desktop set iconViewOptions to icon view options of desktopWindow set iconSize to icon size of iconViewOptions end tell
とやってもデスクトップを開いたFinder window内での表示サイズになってしまいます OS 10.4.10です。
>>448 「Finder でエラーが起きました:icon size of window of desktop を取得できません。」 となります。 set iconSize to icon size of icon view options of window of the desktop とやっても >>447 と同じくFinder window内での表示サイズになってしまいます。
on removing folder items from this_folder after losing these_items tell application "Finder" move this_folder to folder "A" of folder "B" of disk "C" move these_items to this_folder end tell end removing folder items from
move this_folder to folder〜 はスクリプトを付けたフォルダ自身を元のパスに戻すためです。 このパスの指定を一々しないで済むようにできないでしょうか?
>>463 おおっ、ありがとうございます。 あと、List & Record Tools.osax というのを 発見しました(いつの間に入ってたんだろ)。 get user property キー in レコード to 値というのが 使えるようです。 ただ、set user property は破壊的ではないので set レコード to set user property キーin レコード to 値 みたいに書かなきゃいけないのがまぎらわしいですが。
例えば,ガンマを変更する例 tell application "GraphicConverter" activate set selection of window 1 to {50, 50, 500, 500} change gamma of the front window to the 2 end tell
tell application "Finder" set theList to every file of folder "Music" of folder "Data のファイル" of startup disk end tell tell application "QuickTime Player" repeat with aFile in theList open aFile set a to some movie start a repeat until not (playing of a) delay a end repeat close a end repeat end tell
tell application "Finder" set theList to every file of folder "Music" of folder "Data のファイル" of startup disk repeat 100 times --シャッフル回数 set rnd1 to (round ((random number) * listCount) rounding down) + 1 set rnd2 to (round ((random number) * listCount) rounding down) + 1 set keepBox to item rnd1 of theList set item rnd1 of theList to item rnd2 of theList set item rnd2 of theList to keepBox end repeat tell application "QuickTime Player" repeat with aFile in theList open aFile delay 0.5 set a to document 1 start a repeat until not (playing of a) end repeat close a end repeat end tell
tell application "Finder" to ツ set theList to (every file of folder "Music" of folder "Data のファイル" of startup disk) as alias list set num to number of theList repeat with n from 1 to num set rnum to (random number from 1 to num with seed (time of (current date))) set aFile to item rnum of theList set item rnum of theList to "" set theList to every alias of theList tell application "QuickTime Player" open aFile set a to some movie start a repeat until not (playing of a) delay a end repeat close a end tell end repeat
そこで事前に set clipStr to (the clipboard) as text って感じでクリップボードの内容を変数に入れておいてフォーカスしたフィールドに入力したいんだけど、この場合はどうすればよいのでしょうか? 「※この部分」の下3行をペーストではなく、clipStrを入力したい、という意味です。
repeat 100000 times set Randon_numer to random number from 1 to 2 if Randon_numer <= 1 then set o_num to o_num + 1 else set e_num to e_num + 1 end if end repeat
repeat 100000 times set Randon_numer to random number from 1 to 2 if Randon_numer ? 1 then set o_num to o_num + 1 else set e_num to e_num + 1 end if end repeat
set startTime to (time of (current date) as integer) - (time of startTime as integer) set min to startTime div minutes set sec to startTime mod minutes if min < 10 then set min to "0" & min as string if sec < 10 then set sec to "0" & sec as string
set a to {0, 0, 0, 0, 0, 0, 0, 0, 0, 0} repeat 10000 times set rn to random number from 1 to 10 set item rn of a to (item rn of a as number) + 1 end repeat a
どんなアプリが再全面であってもそのアプリで選択された文字列を確実に取得する方法ってあるのでしょうか? tell application "System Events" keystroke "c" using command down end tell みたいなやり方だとタイミングのせいか、クリップボードには入ってるのに取り出せなかったりして困ってます。
tell application "System Events" tell application "" to activate delay 1-------------------------適当な値 keystroke "c" using command down delay 1-------------------------適当な値 end tell
tell application "System Events" set aName to (name of (path to frontmost application)) set appName to (do shell script "echo " & quoted form of aName & " | sed 's/" & (ASCII character 128) & ".app$//'") end tell tell application appName activate set the clipboard to "" end tell tell application "System Events" set num to 0 repeat until ((the clipboard) is not "" or num = 10) keystroke "c" using command down set num to num + 1 delay 0.5 end repeat end tell
tell application "Finder" to activate delay 3 --この間にシフトキーを押したり押さなかったりしておく tell application "System Events" tell process "Finder" try set thePosition to (position of menu item "強制終了…" of menu "Apple" of menu bar item "Apple" of menu bar 1) thePosition --position of menu item "強制終了…" の値を返す tell application "Finder" activate display dialog "Shift キーが押されていません。" end tell on error --Shift キーが押されている間は menu item "強制終了…" の position は missing value になるので、thePosition は定義されない。従って thePosition を呼び出そうとするとエラーになる。 tell application "Finder" activate display dialog "Shift キーが押されています。" end tell end try end tell end tell
tell application "Safari" set hige to do JavaScript "var moe = escape(window.getSelection()); unescape(moe);" in document 1 set summary to summarize hige display dialog summary end tell
>>540 この書き方はダメだよ。AppleScriptはUnicode化されてなくてスクリプトは エンコーディング変換されて収納される。だから言語設定の影響受けたり 再コンパイル時に壊れる。 面倒でもバックスラッシュ(U+005C)は直書きしない方が良い。 set stg to "a " & quote & "quote" & quote & " mark" set backslash to ASCII character 92 "a back" & backslash & "slash"
tell application "System Events" tell application "Stickies" to activate set hige to count every window of process "Stickies" repeat hige times keystroke "m" using command down key code 118 using control down delay 0.5 end repeat end tell
set x to 30 set y to 40 tell application "System Events" tell application "Stickies" to activate set hige to count every window of process "Stickies" repeat hige times set position of window 1 of process "Stickies" to {x, y} keystroke "m" using command down key code 118 using control down set x to x + 10 set y to y + 15 delay 0.5 end repeat end tell
tell application "Finder" set itemRet to items of (choose folder) log itemRet -->旧名前順? 1<11<2 set itemRet to sort itemRet by name log itemRet -->intel OSX10.4.10(現環境1台のみ) Finderでの名前順 1<2<11 end tell 何処かでファインダの仕様かわってたんだね。ファインダの見た目依存のスクリプトいくつかもってて。 で、OSのバージョンで切り替える為に細かい数字だれか知っていたら教えてほしい。
set alpha to choose file set bravo to POSIX file (alpha as string) set charlie to POSIX path of bravo set delta to charlie as alias tell application "Finder" set echo to container of delta end tell
log alpha log bravo log charlie log delta log echo
set hige to (do shell script "defaults read 〜/Library/Preferences/com.apple.dock | grep -w 'http' | sed 's/\"_CFURLString\" = \"//g' | sed 's/ *//g' | sed 's/\";//g'")
tell application "TextEdit" set moe to make new document set text of moe to hige end tell
set alpha to choose file set bravo to POSIX path of alpha set charlie to bravo as POSIX file set delta to charlie as alias tell application "Finder" set echo to container of delta end tell
log alpha log bravo log charlie log delta log echo
>>631 tell application "System Events" tell process "System Preferences" tell tab group 1 of window 1 click radio button "Sound Effects" click checkbox "Play user interface sound effects" of group 1 end tell end tell end tell
>>632 tell application "System Preferences" activate set current pane to pane "com.apple.preferences.sharing" -- または -- set current pane to pane "Sharing" end tell
set testPath to (choose file) as text my parent_path(testPath, -1)
to parent_path(pathStr, gen) set orgDelim to AppleScript's text item delimiters set AppleScript's text item delimiters to ":" set mam to (text items 1 thru (gen - 1) of pathStr) as text set AppleScript's text item delimiters to orgDelim return mam & ":" end parent_path
---
関数parent_path pathStr 対象アイテムへのパス文字列(文字列であることに注意) gen 何世代さかのぼるか。-1で1つ上、-2で2つ上... 結果 さかのぼったパス文字列
on open theObj display dialog "ファイル名末尾に追加する文字列を入力してください。" default answer ".flv" set add_str to text returned of result count item of theObj repeat with i from 1 to result set theObj_path to POSIX path of (item i of theObj as Unicode text) do shell script "mv -f " & quoted form of theObj_path & space & quoted form of (theObj_path & add_str) end repeat beep end open
>>648 tell application "System Events" get item 1 of startup disk --> file "Macintosh HD:.DS_Store" get item 1 of startup disk as alias --> alias "Macintosh HD:.DS_Store" get disk item 1 of startup disk as alias --> 同上
set thelist to {"a", "b", "c"} set triger to 0 set number to 0 repeat while triger = 0 set number to number + 1 if item number of thelist is "b" then set triger to 1 end if end repeat
on indexof(the_item, the_list) set c to count the_list repeat with i from 1 to c if item i of the_list = the_item then return i end repeat return -1 end indexof
set itemPos to listItem(theList, myItem) of me log "リストの" & item itemPos of theList & "は" & itemPos & "番目です"
on listItem(theList, myItem) set i to 1 repeat with oneItem in theList if contents of oneItem is myItem then exit repeat set i to i + 1 end repeat return i end listItem
try set fkaFlg to do shell script "defaults read 'Apple Global Domain' AppleKeyboardUIMode" on error set fkaFlg to "0" end try if fkaFlg is "0" then tell application "System Events" to key code 98 using control down end if
アプレット側:myApplet.app property myprop : "my property" on open() display dialog "OPEN" end open on ?event xxxxyyyyy? display dialog "YES!" end ?event xxxxyyyy?
スクリプト側 tell app "myApplet.app" get myprop #->my property ?event xxxxyyyyy? #-> YES! end app
on adding folder items to this_folder after receiving these_items do shell script "chgrp ore; chmod 774 " & quoted form of (POSIX path of these_items) password "YOUR_PASSWORD" with administrator privileges end adding folder items to
on adding folder items to this_folder after receiving these_items repeat with f in these_items set pass to "YOUR_PASSWORD" set grop to "YOUR_GROUP" set posf to quoted form of (POSIX path of f) set com1 to "chgrp " & grop set com2 to "chmod 774" repeat with c in {com1, com2} do shell script (c & " " & posf) password pass with administrator privileges end repeat end repeat end adding folder items to
tell application "Finder" --拡張子変換、練習用スクリプト。動作条件-->拡張子がついていて見えること。エラー処理はわざとしていない。注意。 --スクリプトエディタの下のイベントログをクリックして動作すると過程がみえる。一行に一つの処理でかいてあります。 choose file "拡張子を変更したいファイルを選択" -->オープンダイアログをあけてファイルを指定する。 set myfile to result -->変数に格納する。 display dialog "変えたい拡張子" default answer "txt" -->デフォルトをtxtとして入力ダイアログをあける。 set newFileExtension to (text returned of result) as string -->変数に格納する。 --ファイルから情報を取り出す。 set fileExtension to name extension of myfile as string -->ファイルから拡張子を取ってくる。 set fileName to name of myfile as string -->ファイルからファイル名を取ってくる。 --処理開始 set strNum to offset of fileExtension in fileName -->ファイル名の中の拡張子の先頭位置を出す。 set newFileName to text 1 thru (strNum - 1) of fileName -->ファイル名の拡張子の無いものを作る。 log {fileName, newFileName} -->このようにして変数の内容は確認する。 set newFileName to newFileName & newFileExtension -->入力した拡張子を後ろにつける。 set name of myfile to newFileName -->ファイル名を変更する。 end tell
set theLocation to location of theTrack set newLocation to "Desktop/hoge.pdf" tell application "Finder" to duplicate file theLocation to file newLocation of home
end repeat end tell
こうすると、 Finder でエラーが起きました:file "Desktop/hoge.pdf" of home を file (alias "070918 10.4.10 bak:Users:foo:Music:iTunes:iTunes Music:Bar:aho.pdf") に設定できません
set newLocation to (alias "Macintosh HD:Users:foo:Desktop:" & i & ".pdf") do shell script "touch /Users/foo/Desktop/" & i & ".pdf" tell application "Finder" to duplicate file theLocation to file newLocation
tell application "Safari" set curl to URL of document 1 open location curl do JavaScript "window.open('curl','win2');" in document 2 do JavaScript "location.reload(true);" in document 2 set bounds of window 1 to {0, 22, 640, 1000} set bounds of window 2 to {640, 22, 1280, 1000} end tell
tell application "Safari" set curl to URL of document 1 make new document with properties {URL:curl} set bounds of window 1 to {0, 22, 640, 1000} set bounds of window 2 to {640, 22, 1280, 1000} end tell
10.4か10.5かを知りたいだけなら,Finderのバージョンで分岐して, set finderVersion to version of application "Finder" if finderVersion starts with "10.4" then 〜〜 else if finderVersion starts with "10.5" then 〜〜 end if という手もありそうです。
on open droppedItem tell application "Finder" repeat with curltem in droppedItem myAliasToSymbolicLink(curltem) end repeat end tell end open
on myAliasToSymbolicLink(curltem) tell application "Finder" if class of ((properties of curltem) as record) is folder then set the childList to every folder of curltem repeat with i from 1 to number of items in the childList set iItem to item i of the childList open iItem my myAliasToSymbolicLink(iItem) close window of iItem end repeat end if if class of ((properties of curltem) as record) is alias then set myPos to position of curltem set myAliasPath to (POSIX path of curltem) as Unicode text set myOrignalPath to (POSIX path of original item of curltem) as Unicode text erase curltem do shell script "ln -s " & quoted form of myOrignalPath & " " & quoted form of myAliasPath end if end tell end myAliasToSymbolicLink
AppleScrpt Studioで質問。 windowにNSDatePickerを配置したのですが, これに現在時刻を設定したいのです。ためしに set date value of text field "myDate" to current date としても,エラーでした。 フィールドのクラスをどうすればよいのでしょうか?
>>772 NSDatePickerのAS上でのclassはcontrolだから set content of control "myDate" of theObject to current date とか set content of control "myDate" of theObject to (call method "dateWithTimeIntervalSinceNow:" of class "NSDate" with parameter 3600)
set searchWord to " abr-" set text1 to "ツバサ26 abr-2-8-225.mov"
if text1 contains searchWord then set CurDelim to AppleScript's text item delimiters set AppleScript's text item delimiters to searchWord set temp1 to text items of text1 set text1Posi to 1st item of temp1 set text1Posi to (length of text1Posi) + 1 log ("text1 offset : " & text1Posi) set AppleScript's text item delimiters to CurDelim end if
choose file set hoge to result tell application "Finder" set hoge to name of hoge as Unicode text end tell set hoge to do shell script "echo " & hoge & " | iconv -f UTF-8-MAC -t UTF-8" log length of hoge offset of ".zip" in hoge
OS X 10.3で、Finderにてselectしたファイル・フォルダの「アーカイブを作成」するコマンドはないでしょうか? 自宅の10.4にて調べていますがFinder.sdefやネットを見てますが見つかりません('A`) 同様に「ゴミ箱を確実に空にする」コマンドはないでしょうか? よろしくお願いします。
フォルダアクションを勉強するためにフォルダにアイテムが追加されたら アイテムの名前を表示するスクリプトを考えているのですが on adding folder items to this_folder after receiving added_items tell application "Finder" set namae to the name of added_items end tell display dialog namae end adding folder items to このように書いても何のダイアログも表示されません、とりあえず 追加されるアイテムは必ず1個ということにして複数は想定してません set namae to the name of added_itemsのadded_itemsをthis_folder に変更するとアイテムの追加されたフォルダの名前はちゃんと表示してくれるのですが アイテムの名前を取得する場合は、書き方が違うのでしょうか?
on open droppedItem tell application "Finder" repeat with iItem in droppedItem my mySetIconViewMode(iItem) end repeat end tell end open
on mySetIconViewMode(curltem) tell application "Finder" --display dialog class of curltem as string open curltem if class of ((properties of curltem) as record) is folder then set toolbar visible of window of curltem to false set statusbar visible of window of curltem to true set current view of window of curltem to icon view set icon size of icon view options of window of curltem to 16 set text size of icon view options of window of curltem to 10 set label position of icon view options of window of curltem to right set arrangement of icon view options of window of curltem to snap to grid
set the childList to every folder of curltem repeat with iItem in childList my mySetIconViewMode(iItem as alias) end repeat end if close window of curltem end tell end mySetIconViewMode
on open droppedItem tell application "Finder" repeat with curltem in droppedItem my myAliasToSymbolicLink(curltem) end repeat end tell end open
on myAliasToSymbolicLink(curltem) tell application "Finder" set the childList to every file of curltem repeat with iFile in childList if kind of ((properties of iFile) as record) is "エイリアス" then if kind of original item of iFile is "フォルダ" then set myAliasPath to POSIX path of (iFile as Unicode text) set myOrignalPath to POSIX path of (original item of iFile as Unicode text) set myOrignalPath to text from character 1 to ((length of myOrignalPath) - 1) of myOrignalPath delete iFile do shell script "ln -s " & quoted form of myOrignalPath & " " & quoted form of myAliasPath end if end if end repeat
set the childList to every folder of curltem repeat with iFolder in childList my myAliasToSymbolicLink(iFolder as alias) end repeat end myAliasToSymbolicLink
tell application "Finder" set screenBounds to bounds of the window of the desktop set limY to item 4 of screenBounds set allWindows to Finder windows set defWin to {} set vy to {} set wy to {} set windowCount to count of allWindows set defV to 0 repeat with i in allWindows set pos to position of i set bou to bounds of i set defWin to defWin & {pos} set vy to vy & windowCount - defV set wy to wy & (item 4 of bou) - (item 2 of bou) set defV to defV + 1 end repeat
copy vy to defvy copy defWin to activeWin repeat 200 times repeat with i from 1 to windowCount set position of Finder window i to item i of activeWin set item 2 of item i of activeWin to (item 2 of item i of activeWin) + (item i of vy) set item i of vy to (item i of vy) + (item i of defvy) if item 2 of item i of activeWin > limY then set item 2 of item i of activeWin to 0 - (item i of wy) set item i of vy to item i of defvy end if end repeat end repeat set winNo to 1 repeat with i in allWindows set position of i to item winNo of defWin set winNo to winNo + 1 end repeat end tell
on open drop_items try do shell script "" with administrator privileges on error msg number val display dialog msg buttons {"OK"} default button 1 return end try repeat with this_item in drop_items set jpPath to (this_item as string) & "Contents:Resources:Japanese.lproj:InfoPlist.strings" set enPath to (this_item as string) & "Contents:Resources:English.lproj:InfoPlist.strings" tell application "Finder" exists (file (jpPath & ".bac")) end tell if result then do shell script "mv " & quoted form of POSIX path of (jpPath & ".bac") & " " & quoted form of POSIX path of jpPath with administrator privileges else open for access (file jpPath) try set jpText to (read (file jpPath) as Unicode text) end try close access (file jpPath) open for access (file enPath) try set enText to (read (file enPath) as Unicode text) end try close access (file enPath)
--続き set replacedFlag to false repeat with CFName in {"CFBundleName", "CFBundleDisplayName"} if (offset of CFName in jpText) /= 0 then set jpText to my replaceCFName(CFName, jpText, enText) set replacedFlag to true end if end repeat if replacedFlag then do shell script "mv " & quoted form of POSIX path of jpPath & " " & quoted form of POSIX path of (jpPath & ".bac") with administrator privileges do shell script "echo " & "¥"" & jpText & "¥"" & " | iconv -t UTF-16 > " & quoted form of POSIX path of jpPath with administrator privileges end if end if end repeat beep display dialog "完了しました。
結果を反映させるために、Finderを再起動してください。" buttons {"OK"} default button 1 with icon POSIX file "/System/Library/CoreServices/CoreTypes.bundle/Contents/Resources/FinderIcon.icns" end open
--さらに続き on replaceCFName(CFName, jpText, enText) set Locat to (offset of CFName in enText) set TextLength to length of enText set enText to (text from Locat to TextLength of enText) set Locat to (offset of ";" in enText) set enName to (text 1 thru (Locat - 1) of enText)
set TextLength to length of jpText set Locat to (offset of CFName in jpText) set textHead to (text 1 thru (Locat - 1) of jpText) set jpText to (text from Locat to TextLength of jpText) set TextLength to length of jpText set Locat to (offset of ";" in jpText) set textBottom to (text from Locat to TextLength of jpText)
set resultText to textHead & enName & textBottom return resultText end replaceCFName
set theText to get the clipboard set backslash to ASCII character 128 set searchWd to backslash if (offset in theText of searchWd) = 0 then else set theText to my replaceTxt(theText, backslash, "/") --置換一つ目 set theText to my replaceTxt(theText, "//hoge", "/Volumes") --置換二つ目 display dialog theText end if
on replaceTxt(myText, searchTxt, replaceTxt) set oldDel to AppleScript's text item delimiters set AppleScript's text item delimiters to searchTxt set myText to every text item of myText set AppleScript's text item delimiters to replaceTxt set myText to myText as string set AppleScript's text item delimiters to oldDel return myText end replaceTxt
delay 1 tell application "Safari" to activate repeat with Var from 1 to 10 tell application "System Events" keystroke tab keystroke tab keystroke tab keystroke tab delay 1 keystroke Var keystroke "]" using {command down, shift down} end tell end repeat
Safari3のタブ切り替えすげー! tell application "Safari" activate repeat with i from 1 to (number of tabs of window 1) set current tab of window 1 to tab i of window 1 end repeat end tell
ちなみにdo JavaScriptならタブ切り替えなくてもフォームに入力できるみたい。 3つのタブでhttp://www.google.co.jp/を開いてるとして tell application "Safari" repeat with i from 1 to 3 do JavaScript "document.forms[0].elements[1].value='0000" & (i as string) & "'" in tab i of window 1 end repeat end tell
スクリプト側(シェルやらRubyやらPerlやら)からAppleScriptを呼び出して、 エイリアスを作る処理をしたいのですが、一部のファイル名で 65:66: syntax error: Expected メ"モ but found unknown token. (-2741) のエラーが出ます。たしか、感じのコードの中にエスケープコードが含まれているから、 みたいな理由だったったお思います。どうすればいいでしょう。お知恵拝借。 テスト用のスクリプトです #!/usr/bin/ruby -Ku require 'iconv' require 'nkf' def make_alias(path, dest) utfPath = Iconv.conv('UTF-8', 'UTF-8-MAC', path) utfDest = Iconv.conv('UTF-8', 'UTF-8-MAC', dest) scpt = NKF.nkf('-Lms', <<-EOS) set targetFile to "#{utfPath}" as Unicode text as POSIX file as alias set targetFolder to "#{utfDest}" as Unicode text as POSIX file as alias tell app "Finder" to make alias file to targetFile at targetFolder EOS scpt.gsub!(/'/){%Q!'"'"'!} return NKF.nkf('-Luw', `osascript -e '#{scpt}'`) end DATA.read.split("\n").map{|item| result = make_alias(item, '/Users/tamakiss/Desktop/myFolder') puts item if result.empty? } __END__ /Users/tamakiss/Desktop/ドリームシップ エピソード1/2/info.txt /Users/tamakiss/Desktop/男はソレを我慢できない/info.txt
こうかな #!/usr/bin/ruby -Ku require 'uri' def make_alias(path, dest) utfPath = URI.escape(path) utfDest = URI.escape(dest) scpt = <<EOS set utfPath to (do shell script "echo -n " & quoted form of "#{utfPath}" & " | ruby -Ku -ruri -ne 'print URI.unescape(¥$_)'") set destPath to (do shell script "echo -n " & quoted form of "#{utfDest}" & " | ruby -Ku -ruri -ne 'print URI.unescape(¥$_)'") set targetFile to (POSIX file utfPath) set targetFolder to (POSIX file destPath) tell app "Finder" to make new alias file at targetFolder to targetFile EOS scpt.gsub!(/'/){%Q!'¥¥''!} return `osascript -e '#{scpt}'` end DATA.read.split("¥n").map{|item| result = make_alias(item, '/Users/tamakiss/Desktop/myFolder') puts item if result.empty? } __END__ /Users/tamakiss/Desktop/ドリームシップ エピソード1/2/info.txt /Users/tamakiss/Desktop/男はソレを我慢できない/info.txt
いけそう set astid to AppleScript's text item delimiters set AppleScript's text item delimiters to "," try set num_str to {"01200", "0003405", "0678009"} as string set num_list to (run script "{" & num_str & "}") set AppleScript's text item delimiters to astid on error set AppleScript's text item delimiters to astid end try num_list