>>4 なんか俺、ものすごく基本的なことで間違ってる? tell application "Finder" set a to "/User/xxxx/Desktop/" set POSIX file a open a end tell とすると開けないし、そもそもイベントログ見ても get POSIX file〜でエラー出てる。 POSIX fileの文字列は同様にして tell application "Finder" set a to selection as alias set a to POSIX path of a end tell で得た文字列なので間違いないと思うんだけど、、、、、、。
6 :
間違えました。 tell application "Finder" set a to "/User/xxxx/Desktop/" set a to POSIX file a ←この行 open a end tel でした。l
set a to POSIX file a を tell application "FInder" 内のままで tell me to set a to POSIX file a としてもおけ 他にもっとカッコいい書き方あるかな??
11 :
set a to a as POSIX file
12 :
それはカッコいいっ!ぐぬぬっw
13 :
fileキーワードの解釈が衝突してるんだろうね。my付けてglobalな定義優先すれば良い。 homeのパスも直書きせずこんな感じで。 tell application "Finder" set homePath to POSIX path of (home as alias) set aPath to homePath & "Desktop/" open my POSIX file aPath end tell
on awake from nib theObject tell theObject to register drag types {"file names"} end awake from nib on drop theObject drag info dragInfo set dataTypes to types of pasteboard of dragInfo if "file names" is in dataTypes then set preferred type of pasteboard of dragInfo to "file names" set theFiles to contents of pasteboard of dragInfo set theFiles to POSIX file theFiles tell application "Finder" set theFiles to theFiles as alias duplicate theFiles to desktop end tell end if return true end drop あーもうわからん。テーブルやBoxにドラッグアンドドロップしたら そのオブジェクトをデスクトップにコピーするスクリプトを初歩の初歩 としてサンプルスクリプトを参考にいじっているのだが、うまくいかんorz 上の例でなんとかコピーはされるのだが、なぜかたった数十字のテキスト ファイルでも20秒くらい時間がかかる。明らかにおかしい。でも どこが悪いかわからない。duplicateもtell "Finder"しなくてもいいような 気がするけど、こうじゃないとエラーを吐く。なんで???
18 :
Drag and Drop及びAppleScriptの処理(tell application) はアプリケーション間通信(AppleEvent)を通じで行なわれている Finderはアプリケーション間通信は1度には1つしか行なわない FinderからそのAppleScriptアプリへ通信中(on drop を抜けるまで)に、そのAppleScriptアプリからFinderと通信(tell application "FInder")を行なおうとするので、Drag and Dropの通信中なので止まる Drag and Dropの通信が時間切れになって、やっとこさduplicateが行なわれる てとこかなあ on drop で tell application "Finder" せずに、property に対象をセットし、on idle でそれをチェックして tell application "Finder" するとスムースに行くよ(1秒間隔のチェックなのでちょっと間があるけど) AppleScriptで遅延ハンドラ呼び出しってなんかあったかなあ
19 :
あと、 set theFiles to POSIX file theFiles って、地道に1個ずつ処理しなければなさげだけど? こんなんできんのかっ!と思ったけど、複数ドロップだとエラるようだけど
20 :
StandardAdditions のライブラリより > POSIX file n : A file object specified with a POSIX (slash)-style pathname そりゃそうだろうね あとdupulicateはFinderのcommandだから当然tellってないと無理
21 :
非常にキケンなコードができましたw ほかへの影響はまったく考慮なしw これ、実装してみようかなw 10ファイルくらいなら問題なさそうw on awake from nib theObject tell theObject to register drag types {"file names"} end awake from nib on drop theObject drag info dragInfo set dataTypes to types of pasteboard of dragInfo ignoring application responses ←危険な香り if "file names" is in dataTypes then set preferred type of pasteboard of dragInfo to "file names" set theFiles to contents of pasteboard of dragInfo set FileList to {} ←適当に複数ファイルも対応してみました repeat with aFile in theFiles set aFile to POSIX file aFile set end of FileList to aFile end repeat tell application "Finder" duplicate FileList to desktop end tell end if end ignoring return true end drop >>20 duplicateはFinderのコマンドというのはなんとなく分かるのですが、 自分が作ったアプリの用語辞書にはduplicateが載ってる。 それってつまり、もともとのテンプレートがduplicateに対応している のかな、と。
ちなみに、AppleEvent(をFinder)は一度には一つだけ処理しないけど、キューはあるから、どこどこメモ置いていっても構わないよ 例えば repeat with theItem in FileList duplicate theItem to desktop end repeat でも構わない(まあ、あんまりキューに貯めるのはよくないし、これだと、エフェクト音が煩いしw) なので特にそれだけでは危険というわけでもなく、単にエラー処理ができないってだけだね
>>21 確かにduplicateは載ってるね だけど比べてみると多少内容は違うみたい FinderのStandard Suite >duplicate v : Duplicate one or more object(s) >duplicate specifier : the object(s) to duplicate >[to location specifier] : the new location for the object(s) >[replacing boolean] : Specifies whether or not to replace items in the destination that have the same name as items being duplicated >[routing suppressed boolean] : Specifies whether or not to autoroute items (default is false). Only applies when copying to the system folder. >[exact copy boolean] : Specifies whether or not to copy permissions/ownership as is >→ specifier : to the duplicated object(s) Finder以外のStandard Suite >duplicate v : Copy object(s) and put the copies at a new location. >duplicate specifier : the object for the command >[to location specifier] : The location for the new object(s). >[with properties record] : Properties to be set in the new duplicated object(s). objectをコピーする点は変わりないのだけど、じゃあobject=fileとかの定義があんのかってーと、 自作アプリには無いんじゃね ちなみにSystem Eventsは後者でしかもfileやらfolderの定義もあるのでじゃあduplicateで複製出来るのか?と思ったら出来ないし その辺の理屈はよくわからん
26 :
ちょっと環境がないから分かりませんし、スレ違いかもしれませんが、ここで質問。 OS10.5でXcode3を使ってapplescriptでプログラミングしています。 OS10.4をターゲット?にしてコンパイルして10.5と10.4でプログラムを 動かしていました。しかし、10.5のほうは快調に動いていますが、 10.4でよく分からないのですが、特定の条件でエラーを吐きます。 Finder can't get Unknown objectとかなんとか。 実際にはDVDなどのメディアをFinder上から取得する動作で 詰まっているようです。 tell application "Finder" set DiskDVD to selection as alias end tell というようなことをしているのですが、いろんな種類のメディアで エラーになったりならなかったりします。考えたことは 続きます。
Mail.appで受信ボックスの未読メールを全て選択して.txtに書き出したいのですが、 「未読メールを全て選択」という所がどうやればいいのか分かりません。 check for new mail for account "accountname" keystroke "1" using {command down} こんな感じに、メールを受信して受信ボックスを開いたところまではできたのですが、未読メールを全て選択するにはどうすればいいでしょうか? .txtで書きだすのは、 System Eventを使って pick menu bar 1's menu bar item "ファイル"'s menu "ファイル"'s menu item "別名で保存..." delay 1 keystroke "UnreadMail" keystroke return こんな感じに書きました。
38 :
tell application "Mail" set MessageList to (every message of mailbox "INBOX" of account accountname whose read status is false) set theText to "" repeat with theMessage in MessageList set theText to theText & content of theMessage end repeat end tell みたいな感じで
Skypeでapplescriptの設定する方法教えてくれるかたいませんか? ID co-ca-co-la.jp
41 :
美人集め ※ワールド非対応 set BIJIN to "bijin" display dialog "エリアは" default answer "jp" set AREA to text returned of result display dialog "開始時間は" default answer "0000" set STARTTIME to text -4 thru -1 of ("0000" & text returned of result) display dialog "終了時間は" default answer "2359" set ENDTIME to text -4 thru -1 of ("0000" & text returned of result) set H to text 1 thru 2 of STARTTIME as number set M to text -2 thru -1 of STARTTIME as number tell application "Finder" set picFolder to folder "Pictures" of home set bijFolder to folder BIJIN of picFolder if not (exists bijFolder) then make new folder with properties {name:BIJIN} at defFolder if not (exists folder AREA of bijFolder) then make new folder with properties {name:AREA} at bijFolder end tell repeat set HH to text -2 thru -1 of ("0" & (H as text)) set MM to text -2 thru -1 of ("0" & (M as text)) set CURRENTTIME to HH & MM do shell script "curl -o ~/Pictures/" & BIJIN & "/" & AREA & "/" & CURRENTTIME & ".jpg -e http://bijint.com/jp/http://www.bijint.com/" & AREA & "/tokei_images/" & CURRENTTIME & ".jpg" if CURRENTTIME = ENDTIME then exit repeat set M to (M + 1) mod 60 if M = 0 then set H to (H + 1) mod 24 end repeat 自分の環境だと1日分で10分ちょい
ものすごく基本的なことなんだけどなにやらわからないので教えてくれ。 Xcodeでインターフェイスつけてデータを加工するのだが、毎回毎回繰り返す。 そのとき、前の変数の値を引きずらないように初期化的な処理をするんだが、 どうするのがいいのかよくわからない。 普通の文字列とかなら set a to "" とかすればいいと思うんだけど、ファイルやフォルダなんかを保持する変数の場合 上と同様でいいんでしょうか? 上と同じことをすると変数の型が変わってしまうような。 それから、defaultつーかplistつーかにレコードって保持できるんでしょうか? いまいちどうすればいいかわからない。 どなたかご回答を。
あるクラスのオブジェクトを指定するときにindexを使って以下のようなことができますが、 tell application "iTunes" set aSong to track index 1 of current playlist 逆にある曲の参照番号を知りたいときはどのようにすればいいのでしょうか? 具体的には、以下のようなことがしたいです。 set aTrackNo to |aSongの番号| set bTrackNo to |aTrackIDを加工| play track index bTrackNo of current playlist id of aSong は必ずしも表示順と一致しないので使えませんでした。 またiTunesでは、再生中のものとは異なるプレイリストを表示した状態だとpause中のnext trackが動作しないというバグ?があるようですが、GUIスクリプティング以外にこれをworkaroundする方法はあるでしょうか。 idを使う方法だとシャッフル時はうまくいきません。 長文になってしまいましたがご回答お待ちしております。
70 :
ちょっとやってみた tell application "iTunes" set theID to id of track 1 of current playlist end tell --ある曲が持つ固有の"ID"をtheIDに入れておく tell application "iTunes" set theList to id of tracks of current playlist repeat with i from 1 to count of theList if item i of theList is equal to theID then exit repeat end repeat i end tell --current playlistに含まれる曲のIDのリストを作り、そのリストの中でtheIDの位置を調べる current playlistの並び順は、その時のiTunesでの表示順になっているようです。
71 :
>>69 >またiTunesでは、再生中のものとは異なるプレイリストを表示した状態 iTunes自体がそういうものだからじゃないの。普通に使っていても current playlist に対してだから、current playlist にするために、play してすぐ pause するとか tell application "iTunes" set thePlaylist to playlist "Any playlist of any song"
try if thePlaylist is not current playlist then play thePlaylist pause end if on error play thePlaylist pause end try next track end tell try - on error は current playlist が現在存在していない(iTunes起動直後とか)場合のお
>>72 current playlist が現在見ている/表示している playlist ではないが、その current playlist 内での次の曲ってこと? play next track (必要ならすぐpause) よくわからないけど、play とすぐに pause を組み合わせればどうにでもなりそうだけど
74 :
>>69 曲を取得した時のプレイリストとインデックスを求めるプレイリストが同じなら index of aSong で取得できそうだけど
スマートではないんだけど set xxx to "AAA" set theVal to "{AAA:¥"あああ¥", BBB:¥"いいい¥", CCC:¥"ううう¥"}" set theScript to "get " & xxx & " of " & theVal as string run script theScript set yyy to result
84 :
AとBという対のリストならAのリストで一致した時のアイテム番号でBのリストの要素を指定するとか。
85 :
>>80 -- 対応する値を同じ順番で二つの変数へ入れる set listA to {"a", "b", "c"} set listB to {"あ", "い", "う"} set theVal to "b" -- これが決まった値とする set theNum to offset in (listA as text) of theVal set theResult to item theNum of listB return theResult スクリプト書いてから84と一緒だということに気付いた まあ、せっかくなので晒しとく
>>83の変形版というかrecordを実体で持つ場合 set theKey to "AAA" set theRecord to {AAA:"あああ", BBB:"いいい", CCC:"ううう"} run script "on run {theRecord} |" & theKey & "| of theRecord end run" with parameters {theRecord} recordの持ち方が違うだけなので速度的には同等 パイプは念の為に書いてるけどこの例なら無くても動きます
93 :
もいっちょ 殆ど一緒だけどちょっとだけ速い気がする set theKey to "AAA" set theRecord to {AAA:"あああ", BBB:"いいい", CCC:"ううう"} keyOfRecord(theRecord) of (run script "on keyOfRecord(theRecord) |" & theKey & "| of theRecord end keyOfRecord it") とまぁ書いておいてなんだけど… recordを使う方法は分量は短くなるけど、初見では何をやってるのか解り辛いかもね 2つのlistを使う方が内容的にはシンプル でもって速度的な面でも結局listの方が速いんじゃないかなという気が; いずれにしてもミリ秒以下の話だけども
94 :
もうレコードのキーを取り出すのはあきらめるというのはどうだろう。 set theRec to {{label1:"AAA",Label2:"あああ"},{label1:"BBB",Label2:"いいい"},{label1:"CCC",Label2:"ううう"}} set theKey to "AAA" repeat with i in theRec if label1 of i = theKey then set theResult to label2 of i end repeat 速度が早いかどうかは知りません。 ところでどなたかご存知なら。 フォルダtheFolderの中にあるファイルを取得する命令 set allFiles to every file of theFolder これとほぼ同じことをevery file ofを使わずに実現するにはどうすればいいんでしょう。 do script shell cat POSIX path of theFolder←すんません。知識がなく適当です。 とか call method 〜 とかそんな方法で。なぜか分からないのですが、特定のネットワーク上のフォルダについて every file of を使うとなぜか固まり、まったく原因がつかめないため、違う方法を 試してみたいのです。どなたかヒントを。
95 :
処理時間測定してみた。マシンは2GHz Core i7 素直なループ処理使う方が30倍速い。 (1) 0.65秒 set xxx to "CCC" set theVal to "{AAA:¥"あああ¥", BBB:¥"いいい¥", CCC:¥"ううう¥"}" repeat 1000 times set theScript to "get " & xxx & " of " & theVal as string run script theScript set yyy to result end repeat (2) 0.022秒 on getIndex(aItem, aList) set idx to 0 repeat with x in aList set idx to idx + 1 if (contents of x is aItem) then return idx end repeat return 0 end getIndex set listA to {"AAA", "BBB", "CCC"} set listB to {"あああ", "いいい", "ううう"} repeat 1000 times set yyy to item getIndex("CCC", listA) of listB end repeat
96 :
>>94 set theFiles to do shell script "cd " & quoted form of POSIX path of theFolder & " && /bin/ls -1 | while read item; do [ -f ¥"$item¥" ] && echo ¥"$item¥";done;exit 0" set saveDelimitters to text item delimiters of AppleScript set text item delimiters of AppleScript to return set theFiles to text items of theFiles set text item delimiters of AppleScript to saveDelimitters ¥ はバックスラッシュ
>>96 なんとか分かる部分だけ使って残りはapplescriptで書いて、get every file of 〜を置き換え、 同様にget name of 〜も do shell script "ruby -e \"puts File::basename(" & (POSIX path of theFolder)'s quoted form & ")\"" にすべて置き換えてみたところ、2分15秒かかっていた処理が、1分15秒になりました。 考えて見たら、get every file of とかしたあともいろいろファイル操作しているのですが、 それもUNIXのコマンドのオプションで対応できそう置き換えてみる予定です。 とても勉強になりました。ありがとうございます。
>>111 複数行の選び方次第でできるよ 連続してる行なら delete data rows X thru Y of data source Z 特定のセルの状態で検索するなら delete (data rows whose content of data cell X is Y) of data source Z 一旦自力でリスト化して〜みたいなのは無理だね --delete {data row X, data row Y} of data source Z その場合はループさせて1回ずつ実行するしかない repeat with aRow in {data row X, data row Y} of data source Z delete aRow end repeat
117 :
>>116 あーありがとー。なんとなく分かりますが、実際にプログラムを 動かしているときにmuitiple selectをオンにした場合、Shift+クリック などでrowが複数選択できるようになると思うんだけど、それを set aRows to selected row delete aRows などとしても消えるのは1行のみ。なんか違う概念が必要な気がするけど わかんねーっすorz 全部消すことと1行消すことはできるのだが、、、、、、
>>120 解決した様だけど折角なのでまとめておく selected row 選択している中で最後に選んだ行番号 selected rows 選択している行番号のリスト selected data row 選択している中で最後に選んだ行への参照 selected data rows 選択している行への参照のリスト deleteに直接selected data rowを渡すと無反応 selected data rowsは選択状態が解除されるだけで削除されない set selected rows to {} set selected data rows to {} 実質的にこれらと同じ なので複数行を削除するなら結局repeat使うしかない repeat with anOrder in reverse of (get selected rows of tableView) delete data row anOrder of data source of tableView end repeat もしくは repeat with aRow in (get selected data rows of tableView) delete aRow end repeat
誰かの役に立つかもしれないので覚書メモ 「AI付属の「Collect for Output」スクリプトの、 書き出し先を手動選択でなく~Desktop/Collect4/<filename>+<"_collect">/ にする」 該当箇所を以下のように書き換える: on collectCurrentDoc() tell application "Finder" activate set homePath to POSIX path of (home as alias) set aPath to homePath & "Desktop/collect4" set myFolder to POSIX file aPath as string end tell try tell application "Adobe Illustrator" set docRef to document 1 set mydocname to name of docRef
copy mydocname to CollectName set myFolder to myFolder & CollectName & "_Collect:" set createPath to POSIX path of myFolder set myCommand to "mkdir -p " & quoted form of createPath do shell script myCommand
>>186 path toでもお決まりのフォルダ位置は得られる。 POSIX path of (path to "cusr") -- home POSIX path of (path to "desk") -- Desktop POSIX path of (path to "down") -- Downloads POSIX path of (path to "docs") -- Documents POSIX path of (path to "pdoc") -- Pictures POSIX path of (path to "mdoc") -- Movies POSIX path of (path to <<data TEXTB5646F63>>) -- Music POSIX path of (path to "spot") -- Saved Searches POSIX path of (path to "trsh") -- Trash POSIX path of (path to "font" from user domain) -- Fonts POSIX path of (path to "pref" from user domain) -- Preferences POSIX path of (path to "asup" from user domain) -- Application Support
使うのはどうせone-linerでしょ。 調べるのもshellの文法じゃなくて、コマンドのパラメータの方。 on download(aURL, aPath) do shell script "curl -L " & aURL & " -o " & quoted form of aPath end download set aURL to "http://www.nasa.gov/images/content/616888main_pia15280-43_800-600.jpg" set aPath to (POSIX path of (path to "down")) & "mars_rovers.jpg" download(aURL, aPath) tell application "Finder" to reveal my POSIX file aPath
AppleScriptを使用して、定期的にDDNS(Dynamic Do!)のIPアドレス更新をやりたいのですが、うまく動いてくれません。。 ---- ソース --------------------------------------------- set str_Domain to [ドメイン名] set str_Pass to [パスワード] on idle do shell script "\"http://free.ddo.jp/dnsupdate.php?dn=" & str_Domain & "&pw= " & str_Pass & "\"" return 3600 end idle ------------------------------------------------------ なにか間違っている個所がございますでしょうか??
247 :
すみません訂正です。 curlコマンドが抜けていました。。 ---- ソース --------------------------------------------- set str_Domain to [ドメイン名] set str_Pass to [パスワード] on idle do shell script "curl \"http://free.ddo.jp/dnsupdate.php?dn=" & str_Domain & "&pw= " & str_Pass & "\"" return 3600 end idle ------------------------------------------------------
248 :
"&pw= " 末尾のスペースはソースそのまんま?
249 :
すみません!! スペースはありません。
250 :
>>247 log Result で結果くらい見てみたら? あとメタ文字使わんで、quoted form ofで繋ぐ。 パスワードはhttpで送って大丈夫なのか?
>>261 247です。 変数のスコープというか、AppleScriptでの変数の扱いをよく理解出来ていませんでした。。 下記のソースで、ちゃんと更新が出来ました。 ありがとうございます!! ------------------------------------------------- global str_Domain, str_Pass, str_Cmd set str_Domain to "DOMAIN" set str_Pass to "PASSWORD" set str_Cmd to "curl \"http://free.ddo.jp/dnsupdate.php?dn=" & str_Domain & "&pw=" & str_Pass & "\"" on idle
do shell script str_Cmd return 3600
end idle -------------------------------------------------
script Hoge property hogeprop : "hogeprop" property name : "Hoge" end script script Manager property objects : {} on add(obj) set my objects to my objects & {obj} end add on fetch(str) repeat with obj in my objects if str is obj's name then return obj end if end repeat end fetch end script set oldHoge to Hoge set oldHoge's hogeprop to "hogehoge" tell Manager to add(Hoge) set newHoge to Manager's fetch("Hoge") newHoge's hogeprop 自分には>>270と、これくらいしか思いつかない。 AppleScriptってAppleEventにコンパイルする言語だから、 動的な事をするのが難しいんだよね。 runscriptと文字列処理を幾重にも重ね合わせた事有るけど、 自分で書いてるのに意味不明過ぎてワロタ。
すまん煮詰まってしまった(誤用)ので質問させてくれ iTunesで曲を右クリックすると出てくる「iTunes DJで次に再生」をスクリプトからやらせたい 前提はiTunesがactivateしててその曲がすでに選択済みかつ再生中 UI Scriptingで現在選択中のelementを右クリする方法がよくわからなかったのでとりあえず tell front window of process "iTunes" scroll area 3's outline 1's row whose static text's value begins with "再生中" と行を絞り込もうとしたんだけどエラーが出る 次の方法ならとりあえずstatic textを全回収できるんだけどそこで詰みました set labels to value of scroll area 3's outline 1's rows's static text
>>292 あまりグダグタ書いてもあれかと思い書かなかったが、当然それはやった。 でも、「フォルダ」は削除できないことがある。 で、やはり、>>294に近いスクリプトになったが、ただフォルダ(とその中身)を 消すだけにたいそうなスクリプト書くのもどうなのかと。 aFolderがフォルダーと仮定して tell application "Finder" set aFolder to selection as alias do shell script "rm -rf " & quoted form of POSIX path of aFolder end tell で消えるフォルダもあれば消えないフォルダもある。 削除できない理由が知りたい、という話なんだけど。 実際にフォルダーを消してみて、百発百中完全削除できてるの?
みなさんありがとうございます。 Script自体は結構な長文な上、原因の見当がつかないためベタ張りになってしまうので、 抽象的な質問になるのを承知で控えました。 録画ファイルの自動エンコードやフォルダ分け処理をしています。 基本的には完全放置でフォルダを監視したいのでドロップレットではイマイチです。 途中にやや怪しい箇所があったので書き換えたところ最初の1ファイルで止まることはなくなりましたが、 やはり多数のファイルが入力されると途中で止まってしまうようです。 全体をくくったtry on errorにもひっかからないので、 止まった場合、そもそも処理に突入していない感じがします。 そこで on adding folder items to this_folder after receiving input_items を on open input_items tell application "Finder" set this_folder to (parent of (path to me) as text) as alias end tell としてドロップレットに書き換え試してみたところ、こちらは問題なし。 display dialogを挟むとなぜ動作するのかという疑問は残りますが、 フォルダアクション自体に問題があるのかもしれません。 もっとも、多数のファイルが実際に入力されることはまずあり得ないので、 とりあえずはこのままでいこうと思います。
>>277 確かにSystem Eventsじゃ無理だな。rubyじゃないと。 tell application "Finder" to activate right_cllick(100, 100) selectMenu(1) on right_cllick(x, y) do shell script "/usr/bin/ruby -e 'require '¥¥''osx/cocoa'¥¥''; event=OSX::CGEventCreateMouseEvent(nil, 3, OSX::CGPointMake(" & x & "," & y & "), 0); OSX::CGEventPost(0,event);'" do shell script "/usr/bin/ruby -e 'require '¥¥''osx/cocoa'¥¥''; event=OSX::CGEventCreateMouseEvent(nil, 4, OSX::CGPointMake(" & x & "," & y & "), 0); OSX::CGEventPost(0,event);'" end right_cllick on selectMenu(n) tell application "System Events" repeat n times keystroke (key code 125) end repeat keystroke space end tell end selectMenu
どのレベルかよくわからんので一応補足しとくと if (会社の環境) then --会社での処理 else --自宅での処理 end というようなことだからね この書き方でも共通の部分はユーザ定義ハンドラにしておけば無駄は省ける 全体を丸ごとifで囲むか処理ごとに判定させるかは目的による あと>>1を読んでくれ
質問です。ファイルメーカーで投資信託の管理をしていてヤフーのサイトからその時点での基準価額を引っ張ってくるのに ファイルメーカー内のスクリプトからアップルスクリプトを呼び出して使っていました。そのスクリプトは昔ここで親切な方が教えてくださったものです。 そのアップルスクリプトの参照先のヤフーのアドレスやソースが変わってしまったので参照できなくなり、 書き換えようと思ったのですが私にはできませんでした。もとのスクリプトは set theCode to the clipboard set theNumber to count theCode set theURL to "http://quote.yahoo.co.jp/q?s=" & theCode set theCurl to "curl -s " & quoted form of theURL set theIconv to " iconv -c -f euc-jp -t utf-8 " if "=" is in theCode then set thePerl to "perl -ne 'if( m{<td nowrap align=center>[0-9]+:[0-9]+</td><td nowrap><b>(.*?)</b>} ){ print qq{$1} } '" else if theNumber = 8 then set thePerl to "perl -ne 'if( m{<td nowrap align=center>[0-9]+/[0-9]+</td><td nowrap><b>(.*?)</b>} ){ print qq{$1} } '" else set thePerl to "perl -ne 'if( m{<td nowrap align=center>[0-9]+:[0-9]+</td><td nowrap><b>(.*?)</b>} ){ print qq{$1} } '" end if set theText to do shell script theCurl & " | " & theIconv & " | " & thePerl 以下略(theTextをファイルメーカーに引き渡す) でした。現在のヤフーの参照先は、たとえばtheCode=998405.Tのときは http://stocks.finance.yahoo.co.jp/stocks/detail/?code=998405.T で、そのソース内の <td class="stoksPrice">753.72</td> の部分の数字だけを取ってきたいです(この数字が時間によって変化する)。 このアドレスとソースの変化を元に、書き換えたらよさげなところを書き換えてみましたが、私の能力ではtheTextがからっぽになってしまいます。 どこをどうなおしたらよいか、なにかヒントをいただけたらありがたいです。
すいません、結構基本的なことでしょうが^^; tell application "iTunes" ... repeat with i in x ... set fp to open for access POSIX file "/a/b/c.jpg" ... end repeat ... end tell のopenがコンパイルエラーしてしまいます。 多分iTunesのopen勘違いされているのだと思うのですが、 repeat文の中にあるので。tell applicationを分割することが出来ません。 このように基本命令みたいなのを指すときにはどうしたらよいのでしょうか? OSはMt. Lionです。
387 :
自己解決。 数日前にみてた >>4 が答えになっていました。 tell me to set fp to open for access POSIX file "/a/b/c.jpg" あるいは set fp to open for access POSIX file "/a/b/c.jpg" of me とすれば動きました。
Terminal.appですが、以下のようにしたいのですが、"window"はとれないのでしょうか? tell application "Terminal" set myTab to do script "" set myWin to the container of myTab -- <--こいいうことがやりたい ... ... ... close myWin end tell
396 :
>>395 ここは読んでみた? お望みのことができる気がする AS Hole(AppleScriptの穴) By Piyomaru Software » Terminal.app ttp://piyocast.com/as/archives/category/application_control/terminalapp/ しかし自分も訊きたい 395みたいな、用語辞書でcontainされてると書いてあるclassを得るにはどううればいいんだろうか この場合だと既知のtabからそれを包含してるwindowを得るには……? tab n : A tab. elements contained by windows.
397 :
>>396 ありがとうございます。読んでありました。 書こうとしている内容は >>395 に書いたようなことですが、 お考えと全く同じで、なぜ親のwindowはとれないのか?ということを聞きたかったのでした。 logコマンドに食わせたりするとちゃんと item 1 tab of window id xxxx なんていうふうに知ってるのに。 少し脱線していきますが、 そのASの穴のようにログというか「処理の経過」を出したいのでした。 少し処理が長い(一個が重いand/or多数ファイルを食わせたら)ので、scriptが黙ってしまうのがどうも…と。 ASの穴でのloggerとconsoleを使う案は読みましたが、Terminalでできないのか?と考えてみたのです。 tell application "Terminal" set myTab to do script "" activate --delay set myTTY to (tty of myTab) as string ... ... close myTab -- do script "\nexit 0" in myTab -- ASの穴案。exitの前に一度改行を打ち込んでおいたほうが確実。 ここで、 do shell script "echo 'abc\nxyz\n' >>" & myTTY とやると、ログっぽいことはできます。 欠点はあって、Terminalなので何かキー、特にreturnキーを叩くとログに文字やshellのpromptが割り込んでしまいますし、 偶然 rm * みたいなことを打ち込まれたりするとshellが処理してしまうので問題があると思います。 本当はshell無しでTerminalのウインドウを開きたいのですが(その場合は >> /dev/tty ではだめですが)。
398 :
前の書き込み、close myTabは間違いですね^^; windowオブジェクトが必要(それで、 >>395 の疑問が出たのをすっかり忘れていました…) 連投で、チラ裏になっていきますが… 各shellは必ず別のttyが割り当てられるので、 set myWin to windows whose tty is (tty of myTab) -- becase all tty is unique で親のwindowオブジェクトが取れます。 do shell scriptとして作れば必ずtab一個の新規windowが開くと思うので(あってますか?)、この用途が終わったらclose myWinしてしまっても迷惑をかけないはずです。 この文のwhoseの部分、ttyはwindowのtab elementのpropertyなのに動いてしまうのは、文法的にあっているんでしょうか?
399 :
ところで、windowは一意のid propertyがあるのですがtabにはないので、tabを特定するのにttyを使う(B参照) A: tell application "Terminal" set myTab to do script "" activate set idWin to -1 -- not found flag repeat with myWin in windows -- activateとここの一瞬の隙間にterminalの他のウインドウを前面にされたり、 -- terminal自身が前面でなくなると意図通りに動かない。 if (frontmost of myWin) then set idWin to id of myWin exit repeat end if end repeat .. close window id myWin end tell B: tabオブジェクトそのものを比較出来ない set myWin to -1 -- not found flag repeat with aWin in windows repeat with aTab in every tab of aWin if (tty of aTab = tty of myTab) then -- (aTab = myTab) では絶対 true にならない set myWin to aWin end if end repeat if myWin >= 0 then exit repeat end if end repeat 連投、長文失礼しました。
400 :
>>395 set myWin to item 1 of (windows whose tabs contains myTab) これでいけると思う
401 :
>>399 > if (tty of aTab = tty of myTab) then -- (aTab = myTab) では絶対 true にならない これは aTab が repeat with X in Y の変数だから、 tab 1〜n of window x ではなく a reference to item 1〜n of every tab of window x になってる 故に contents of aTab = myTab としておけば true にもなる >>400 わざわざ item 1 of (windows whose 〜 ) なんてやらんでも、 window 1 whose 〜 で済むよ
402 :
例えば System Events だとフォルダ用に container、 GUI Scripting用に attribute "AXParent" なんてのがあったりするけれど、 AS汎用でこうすれば親が辿れる、みたいな仕組みは無いんだよね でまぁtabの親のwindow取るだけならこんなんとか tell application "Terminal" set myTab to do script "" set myWin to window 1 whose tab of it contains myTab … close myWin end tell 必要ないと思うけど敢えてttyとやらを使うなら tell application "Terminal" set myTty to tty of (do script "") set myWin to window 1 whose tty of tab of it contains myTty … close myWin end tell
403 :
あ、日跨いだのでid変わったけど401=402です ってどーでもいいか
404 :
>>402 >AS汎用でこうすれば親が辿れる、みたいな仕組みは無いんだよね あるよ。 Object specifierのkeyAEContainer parameterが包含するobjectのobject specifier tell application "Terminal" set myTab to do script "" delay 2 close <<class from>> of (myTab as record) end tell
405 :
>>404 あんのかい!…これは恥ずかしい//// …ってかびっくりしたわ でもなんかこれ、<<class from>> がコンパイルで from になるんだけど、 from の状態でもっかい再解釈入るとエラーになっちまうのね はじめから from of と書いてても勿論エラー なんだか微妙な扱いだな… run scriptの中に収めるとか、テキストで保存するとか工夫しないと使い辛い
perl使って文字列置換すると改行コードがLF→CRになってしまいます。 デリミタ使うのを避けたくてperl使ったんですけど、 改行コードも変換されてしまって困りました。 最終的に改行コード変換するためにデリミタ使わないと無理ですか? set LF to ASCII character (10) set CR to ASCII character (13) set str to "test000" & LF & "test111" display dialog "Original text" & return & str & return & ">LF exists=" & (LF is in str) & " CR exists=" & (CR is in str) set str to do shell script "perl -e '$_=$ARGV[0]; utf8::decode($_);s/test/テスト/g; print $_;' '" & str & "'" display dialog "Replaced text=" & return & str & return & ">LF exists=" & (LF is in str) & " CR exists=" & (CR is in str)
410 :
そのスクリプトちゃんと読んでないけど without altering line endings ってのが 用語説明、TN2065
>>412 普通にStandardAdditions.osaxでできるよ。 例えば末尾10byte削りたいなら。 set f to POSIX file "/path/to/file" set fileLength to get eof of f set eof of f to (fileLength - 10)
415 :
>>414 ありがとうございます そのget eofあたりの操作が調べても判らなかったので大げさですが目ウロコです (調べ方が下手なだけとも言えますが) 1つ1つバイナリエディタで削除したっていいよな?と考えているところでした、 本当に助かりました 最終的に下記の形のドロップレットになりました on open of target_files repeat with thefiles in target_files set f to thefiles set fileLength to get eof of f set eof of f to (fileLength - 10) end repeat end open
と思ったらググったら見つかったわ 30秒進める tell application "iTunes" to set player position to (player position + 30) 30秒戻す tell application "iTunes" to set player position to (player position - 30)
448 :
>>446 10秒進める。 tell application "iTunes" if ((player position + 10) > 0) then set player position to (player position + 10) else set player position to 0 end if end tell
フォルダー名をTextEditに書き出したいのですがやり方を教えて下さい これで、結果蘭にフォルダー名が表示されてます set FolderPath to (choose folder with prompt "フォルダを選択") set NameList to (list folder FolderPath) set AppleScript's text item delimiters to return set NameList to every item of NameList as string 最終的には、下のように、2階層のフォルダー名を全てTextEditに保存したいのです AAA(一階層目のフォルダー名) 001(二階層目のフォルダー名) 002(二階層目のフォルダー名) 003(二階層目のフォルダー名) 004(二階層目のフォルダー名) BBB(一階層目のフォルダー名) 011(二階層目のフォルダー名) 012(二階層目のフォルダー名) 013(二階層目のフォルダー名) 014(二階層目のフォルダー名)
451 :
>>450 再帰的にフォルダ内のフォルダを探るハンドラ作って、あとはリストにして、 それを書き込むな。私の場合は。 AppleScript's text item delimiters とかいらんでしょ。
find コマンド使って結果をお好みに編集した方が早いんじゃないの? って最後まで作ってなくて書くけど set FolderPath to (choose folder with prompt "フォルダを選択") set NameList to do shell script "find " & quoted form of POSIX path of FolderPath & " -type d -mindepth 1 -maxdepth 2"
最初のは検索して set FolderPath to (choose folder with prompt "フォルダを選択") set NameList to (list folder FolderPath) set AppleScript's text item delimiters to return set NameList to every item of NameList as string tell application "Finder" set aText to (NameList & return) set aTextFile to open for access ((desktop as text) & "test.txt") with write permission set aEOF to get eof of aTextFile try write aText starting at (aEOF + 1) to aTextFile on error aErrorText display dialog aErrorText end try close access aTextFile end tell これで保存はできましたが、1階層目しか書き出せません 検索するにも用語すら解ってないので、ヒントだけでもお願いします
462 :
3階層目まで、と決まっているなら、 選択したフォルダの中にあるフォルダのフォルダ名をすべて取得 を3回繰り返せばいいだけだよ。 そして、その文字列変数を結合、構成して書き込むデータを作り、 ファイルに書き込むだけ。 delimitersとかまだ難しそうだから使わないほうがいい。 set EveryFile to every folder of 〜 set FileName to name of 〜 repeat with i 〜 if exists then 〜 それからデータ型のリストとエイリアス。基本中の基本だよ。 AppleScriptって普通に書くと本当に自然言語みたいだからまずは なにがしたいのか図にまとめて、それから素直にやるのが吉。
463 :
tell application "Finder" set theFolder1 to every folder of (choose folder) if (count of theFolder1) is not 0 then set theFolderList to "" repeat with i in theFolder1 set theFolderList to theFolderList & name of i & return set theFolder2 to every folder of i if (count of theFolder2) is not 0 then set theFolderList2 to {} repeat with k in theFolder2 set theFolder3 to every folder of k set theFolder3NameList to "" repeat with m in theFolder3 --3階層目のフォルダリストをテキスト化 set theFolder3NameList to (theFolder3NameList & " " & name of m) & return end repeat set end of theFolderList2 to " " & name of k & return & theFolder3NameList as Unicode text end repeat repeat with h in theFolderList2 set theFolderList to theFolderList & h end repeat else set theFolderList to theFolderList & name of i as alias as Unicode text end if end repeat else display dialog "フォルダはありません" end if end tell theFolderList
>>462様 ありがとうございます set EveryFile to every folder of 〜 set FileName to name of 〜 repeat with i 〜 if exists then 〜 これらから検索して参考になりそうなページを見つけ なんとかできそうかなと思っておりましたら その後、一からスクリプトを書いていただき、ありがとうございます 今確認しましたところ結果には希望の形で表示されておりますので どこが間違っているのか、今の私では解りませんが 返された値をみると細かく表示されておりますのでひとつひとつ理解して行きたいとおもいます repeat with i 〜 i以外でもいいのですね 今更ですが、スノレパのアイコン整頓のバグをなんとか改善したく検索すると AppleScriptで出来ると知り、こんな便利なものがあるならもっと他にもできるかなと 調べだしたのが、2週間前です 色んなページのScriptをくっつけて、サイドバー非表示&緑のボタンクリックするScriptを Sparkに登録して便利に使ってます 10年前に発売されたAppleScriptの本でも買って読んだ方がいいのでしょうか? 親切すぎる>>462様 有難うございました。
467 :
tell application "Finder" to if year of (current date) is 2013 then display dialog "あけおめ!"
Adobe イラストレーターで、「非表示のレイヤーを削除する」スクリプトを組もうとしています。 tell application "Adobe Illustrator" set countLayers to count every layer of document 1 repeat with i from 1 to countLayers if visible of layer i of document 1 is false then set visible of layer i of document 1 to true set locked of layer i of document 1 to false delete layer i of document 1 end if end repeat end tell
これだとrepeatもifも不要 tell application "Adobe Illustrator" tell document 1 set delLayers to layers that visible is false set visible of layers to true set locked of layers to false delete delLayers end tell end tell 全レイヤーのロック外れちゃうけど set visible of delLayers to true set locked of delLayers to false だとエラーになる
473 :
tell application "Adobe Illustrator" tell document 1 set delLayers to layers whose visible is false repeat with i in delLayers set visible of i to true set locked of i to false end repeat delete delLayers end tell end tell repeat使っちゃったけどこれならいいんじゃないかな?
デジカメデータを外付HDから何度か移動しているうちに なぜかファイルの"作成日"と"変更日"が移動した日になってしましました 作成日はDeveloper Toolsでないと書き換えできない様なので 変更日をExifの撮影日に書き換えようと下記スクリプトを書きましたが 上手くいきません on open DropObj tell application "Finder" repeat with ObjFiles in DropObj do shell script "/usr/bin/exiftool " & DropObj's POSIX path set modification date of file DropObj to do shell script "/usr/bin/exiftool -DateTimeOriginal" & DropObj's POSIX path end repeat end tell end open 宜しくお願い致します。