d 0107972014/01/23(木) 22:17:46.59ID:iJWTvZ5CP まずすみません。 話題もないみたいだったので、ちょっと賑やかしのために書き込んでみました。 難しいものでもなんでもないけど、スクリプトは下記。
on open dorp_Items tell application "Finder" set aISO to selection as alias end tell set b to do shell script "hdiutil mount " & (quoted form of POSIX path of aISO) tell application "Finder" set tmp to AppleScript's text item delimiters set AppleScript's text item delimiters to tab set fileName to last text item of (b as string) set fileName to (POSIX file fileName) as alias end tell tell application "VLC" activate open fileName end tell end open 0108972014/01/23(木) 22:28:42.30ID:iJWTvZ5CP 続きですが みなさんの指摘どおり、普通にISOをマウントするとフォルダウインドウが開いたり マウントしたディスクを再度再生アプリで開いたりといろいろ面倒で試行錯誤した次第。
サーバー側 property cmdlist : {"curl 'http://ip.ossus.ch'", "ifconfig", "sw_vers"} on cmd(Q) set out to do shell script item Q of cmdlist return out end cmd
tell application "Finder" set thePATH to selection as alias set thePATH to POSIX path of thePATH endt tell set theAnswer to do shell script "ls -a " & quoted form of POSIX path of thePATH displaydialog theAnswer as Unicode text
set Q to choose file --ファイルの場所を取得(Macintosh HD:Users:xxx:Desktop:11.jpg) set Q to POSIX path of Q --POSIX path に変換(/Users/xxx/Desktop/11.jpg) set cmd to "GetFileInfo " & quoted form of Q --コマンドを作成(ここでdo shell scriptでも良いけど、こっちの方がデバッグしやすい) set info to do shell script cmd --コマンドを実行 display dialog "Result" default answer info --結果をダイアログに表示 (*結果はこんな感じ file: "/Users/xxx/Desktop/11.jpg" type: "\0\0\0\0" creator: "\0\0\0\0" attributes: avbstclinmedz created: 02/08/2014 16:20:16 modified: 02/08/2014 16:21:43 *)
フォルダ/ファイルの区別がつく(ファイルの種類もちょっとはつく)、コンテキストメニューを選んだ時点で操作対象が決定しているのでスクリプトが終わるのを待つ必要が無い (スクリプト全てがでなく>>147でいうと set thePATH to selection as alias が実行されるのをだけど) 01521462014/02/08(土) 18:21:39.04ID:nsDgn/AA0 みなさん早速ありがとうございます。 147のやり方でできました。 148は自分にはまだ難しすぎです。勉強します。
on open dropItems --ドラッグ&ドロップされた時の処理とエイリアスリスト repeat with Q in dropItems --入力ファイル数分リピート処理してJPEG イメージのみ変換 tell application "Finder" set itemkind to get kind of Q end tell if itemkind is "JPEG イメージ" then set DropPOSIX to POSIX path of Q set pngOutPath to DropPOSIX & "幅30.jpg" set comd to "sips --resampleWidth 30 " & quoted form of DropPOSIX & " --out " & quoted form of pngOutPath --コマンド作成 do shell script comd --コマンド実行 else --jpegイメージ以外はパス end if end repeat end open --作って思ったけどドラッグ&ドロップはデバッグしづらくて作るの面倒いね 0155名称未設定2014/02/08(土) 20:09:51.56ID:3lSTg7G/0>>154 あ、pngOutPathになってるけど気にしないでね 最初jpgをpngに変化するやつ作ったんだけど分かりづらいから、サイズ変換にした名残です、、、 0156名称未設定2014/02/08(土) 21:00:15.65ID:RuZJBi5i0>>154 >--作って思ったけどドラッグ&ドロップはデバッグしづらくて作るの面倒いね
処理本体は別のハンドラにしておいて、 デバッグする時はrunハンドラから適当なエイリアスのリストを渡すようにすれば、 スクリプトエディタでも動作確認できるぜ ざっくりやるならchoose file/folderの結果がそのまま使える 0157名称未設定2014/02/08(土) 22:26:25.46ID:tRhLBcwSP>>154 素朴な疑問ですみませんが、なんで変数にQなんてとるの? 見たことないんだけど意味あるの? やっぱりrepeat with とくれが i t s くらいで、そのあと小文字でp q r あたり使うのが普通だと思うんだけど。 大文字でQってなんかすごく自己主張が激しいというかw それに普通の変数に1文字変数とかあとで面倒でしょ。
画像を大量に人に渡すときにターミナルで cd でフォルダに移動して sips -s format jpeg *.tif sips -Z 2000 *.tif for nm in *.tif; do mv $nm ${nm%.tif}.jpg; done アプリを使うよりも全然早いのでよく使います。 教えてもらった奴で似たことができそうですね。 いろいろいじくって試してみます。 ありがとうございました。 0160名称未設定2014/02/08(土) 23:13:29.55ID:3lSTg7G/0>>156 そっかそっかなるほどね ありがと! 実際似たような事して作ってたんだけど、エイリアスのリスト作るのとか そもそもon open の中身がどうなってるかってところで一瞬躓いてたわwww >>157 なんでと言われても、、、普通とかあるのか独学すぎてそういうルーティン的なのしらんのよ ごめん シフト+Qって押しやすいし目立つから、特に理由ないよ、英語力無いしスペルミス怖いからテスト時の使い捨て変数にqqqとかzzzとかも使う 最終的には辞書見て直すけどさorz
副産物置いとくね エイリアスリストをつくるハンドラ2つ set aliaslist1 to AliasListGen("/Users/xxx/Desktop/test/") set aliaslist2 to choosefile("jpgとpngだけ", {"jpg", "png"}, true, false) --######################## on AliasListGen(Directory) --入力されたDirectory(POSIXパス)にあるすべてのファイルをaliasリストにするハンドラ set aliaslist to {} set filelist to list folder Directory repeat with Q in filelist set tmppath to Directory & Q set tmpalias to POSIX file tmppath as alias set end of aliaslist to tmpalias end repeat return aliaslist end AliasListGen --######################## on choosefile(prom, seltype, multSel, inv) --(ダイアログに表示される文字列,選択できるファイルタイプリスト,複数選択できるか(Bool),不可視ファイルの表示(Bool)) set deskpath to path to desktop --初期フォルダ設定 choose file with prompt prom of type seltype default location deskpath multiple selections allowed multSel invisibles inv end choosefile 0161名称未設定2014/02/09(日) 05:17:21.79ID:G4uzaK290>>159 画像変換スクリプト作ってみたよ!>>160のAliasListGenハンドラ使ってるから追加してください。 set Convfolderpath to POSIX path of (choose folder with prompt "choose folder") repeat display dialog Convfolderpath & " Please input width" default answer "2000" buttons {"Cancel", "TIFF", "JPEG"} default button 3 with title "Image Conversion" copy the result as list to {intext, selbutton} try if (intext as number) > 0 then exit repeat end try end repeat set OutPath to Convfolderpath set aliaslist1 to AliasListGen(Convfolderpath) if selbutton is "JPEG" then ConvProcess("JPEG", intext, ".jpg", aliaslist1, OutPath) else if selbutton is "TIFF" then ConvProcess("TIFF", intext, ".tif", aliaslist1, OutPath) end if on ConvProcess(format, inWidth, Extension, itemlist, outpathPOSIX) set tmpnum to 0 repeat with initem in itemlist --JPEG, PNG, TIFFのみ変換 (日本語環境のみ) tell application "Finder" to set itemkind to get kind of initem if itemkind is "JPEG イメージ" or itemkind is "PNG イメージ" or itemkind is "TIFF イメージ" then set tmpnum to tmpnum + 1 tell application "Finder" to set itemname to get name of initem set ConvitemPOSIX to POSIX path of initem set itemname to do shell script "echo " & quoted form of itemname & " |sed -e 's/.[^.]*$//g'" set outitemPOSIX to outpathPOSIX & "[" & tmpnum & "]" & itemname & Extension do shell script "sips -s format " & format & " --resampleWidth " & inWidth & " " & quoted form of ConvitemPOSIX & " --out " & quoted form of outitemPOSIX end if end repeat end ConvProcess 0162名称未設定2014/02/09(日) 05:38:49.19ID:G4uzaK290 文字数制限厳しくて変な英語に変えたりコメントとかエラー処理とか色々端折ってますorz 入力値の全角半角とか処理とか追加すると良いかも
てかぶっちゃけリピート処理だとシェルスクリプトだけの方が処理は早いと思う フォルダのパスを取得して cdしてパイプでつないでsips -s format jpeg -Z 2000 *.tif でまとめて変換した方が速いんじゃないかな。
そえば tell application "Finder" to set itemkind to get kind of initem と set itemkind to kind of (info for initem) ってどっちが速いんだろ何回かmsecで時間計ってみたら、後者の方が速い気もしたんだけど、logの表示がうざったいからtellにしました。 あとget kindとかの英語以外での環境での英語表示とかどうやるんだっけ? これだと環境依存で気持ち悪いなー 0163名称未設定2014/02/09(日) 07:12:57.69ID:Eetg+bKV0 UTIを使いましょう。
>>154 "JPEG イメージ"は移植性が無い。 >tell application "Finder" >set itemkind to get kind of Q >end tell >if itemkind is "JPEG イメージ" then if (type identifier of (info for Q) = "public.jpeg") then
>>160 これだと拡張子無しや".jpeg"は拾えない。 >set aliaslist2 to choosefile("jpgとpngだけ", {"jpg", "png"}, true, false) set aliaslist2 to choosefile("jpgとpngだけ", {"public.jpeg", "public.png"}, true, false) 0164名称未設定2014/02/09(日) 08:47:41.45ID:G4uzaK290>>163 choose fileのタイプにtype identifier指定できたんだ なるほどいいね!
てことで>>163さんのアドバイスどおり >>161の tell application "Finder" to set itemkind to get kind of initem if itemkind is "JPEG イメージ" or itemkind is "PNG イメージ" or itemkind is "TIFF イメージ" then
を
try set itemkind to type identifier of (info for initem) on error set itemkind to "" end try if itemkind is "public.jpeg" or itemkind is "public.png" or itemkind is "public.tiff" then に変更します。
NSThreadに関して言えばGCオンで動作はするものの、処理終了までメインがかなりの確率でロックされる、たまにロックされないんだけど、 一応NSThreadの isMainThreadで確認するとinitWithTargetで投げた処理は別スレッドになってるみたいなんだけどなんでだろ ここら辺詳しい方教えてください 0172名称未設定2014/02/22(土) 04:27:05.52ID:7VQSd7JC0 手持ちのプログラムでちょっと検証してみたら AVCaptureSessionのstartRunningでGCのエラーログが出るんじゃなくて SessionのinputsにAVMediaTypeAudioがセットされた状態でstartRunningすると出るみたい 試しにAVMediaTypeVideoでFaceTime CameraをセットしてstartRunningしたら出なかった もちろんカメラは起動してる NSSoundの件もあるし音関係を扱うと出る可能性があるかも やっぱりGCのバグぽい? それならと思ってaudiotoolboxで鳴らしてみようと適当に書いてみたら、 スタート後少し待ってfreeなんちゃらってでて鳴らなかった、適当だったから書き間違いかもだけど。。。 疲れたからとりまここまで、誰か解決策plz Mt.lionやMarvでも同じ症状でるのかな そもそもMt.lionからARC対応したからARCでいけるのか? NSSoundで音が鳴り終わったらエラーが出るサンプル作ったから、試してみて下しあ ボタン押すとシステムサウンドが鳴ってエラーがあった場合コンソールに表示されます。 ↓ 0173名称未設定2014/02/22(土) 04:28:26.91ID:7VQSd7JC0 property ca : current application on run set BK to ca's NSBackingStoreBuffered tell ca's NSWindow's alloc() initWithContentRect_styleMask_backing_defer_({{300, 300}, {200, 100}}, 3, BK, false)'s autorelease() setTitle_("NSSoundTest") set wind to it end tell tell current application's NSButton's alloc() tell initWithFrame_({{0, 0}, {90, 24}}) setTitle_(" Play ") setTarget_(me) setBezelStyle_(1) setAction_("Play:") set button to it setTranslatesAutoresizingMaskIntoConstraints_(false) end tell end tell set conview to wind's contentView conview's addSubview_(button) set xx to current application's NSLayoutAttributeCenterX set yy to current application's NSLayoutAttributeCenterY set xx_con to current application's NSLayoutConstraint's constraintWithItem_attribute_relatedBy_toItem_attribute_multiplier_constant_(conview, xx, ca's NSLayoutRelationEqual, button, xx, 1, 0)'s autorelease() set yy_con to current application's NSLayoutConstraint's constraintWithItem_attribute_relatedBy_toItem_attribute_multiplier_constant_(conview, yy, ca's NSLayoutRelationEqual, button, yy, 1, 0)'s autorelease() conview's addConstraint_(xx_con) conview's addConstraint_(yy_con) wind's makeKeyAndOrderFront_(me) end run on Play_(sender) ca's NSSound's soundNamed_("Submarine")'s play() end Play_ 0174名称未設定2014/02/25(火) 09:54:30.60ID:sBemAXSz0 だ、だれも試してくれてない。。。 OS依存なのかだけでも知りたいな マウンテンライオンかマベの方いたら、どうかお願いします。 動作反応見る感じAppleScriptエディタだと 標準でGCC_ENABLE_OBJC_GCがrequiredでコンパイルされるみたい。 CFAbsoluteTimeGetCurrent使えるし エラー出るし、、、
windowとかをわざわざ作らないでchoose from list使って簡略化しました、再生される音も選べるようにしました。 CFAbsoluteTimeGetCurrent使ってタイトルに時間表示してます ちなみにlionだと 選択したSEが再生され、音が鳴り終わるごとにコンソールにerrログが出力されます。 ログが出るかでないかだけでも教えてもらえれば幸いです
on run repeat set nowtime to (current application's CFAbsoluteTimeGetCurrent()) div 1 set SEList to {"Basso", "Blow", "Bottle", "Frog", "Funk", "Blow", "Glass", "Hero", "Morse", "Ping", "Pop", "Purr"} set selSE to choose from list SEList with prompt "再生するSEを選択" OK button name "Play" with title nowtime if selSE is false then quit me else my play(item 1 of selSE) end if end repeat end run on play(SEName) current application's NSSound's soundNamed_(SEName)'s play() end play 0175名称未設定2014/02/25(火) 11:13:11.62ID:PY34aknD0 AppleScriptObjCでGCだのARCだのっつうからXcodeでかと思ったらAppleScript Editorでかよっ、しかもなんかちょうちょっと古いOSかよっと思った ID: 7VQSd7JC0 から ID: 9KWp105h0 へのかと思ったしな
Finderにてリスト表示の幅を調整するにはどうしたらいいのでしょうか? アドバイスなどよろしくお願いします。 0180名称未設定2014/03/29(土) 16:08:35.33ID:e5Jihre30 とりあえず動いた property vwList : {{v:"name", w:300}, {v:"dateAdded", w:200}, {v:"label", w:150}} -- vは{"name", "dateModified", "dateCreated", "dateLastOpened", "dateAdded", "size", "kind", "version", "comments", "label"}のどれか。下記(*1)を参照。 on getW(argV) repeat with itemX in vwList if v of itemX is argV then return w of itemX end if end repeat return 0 end getW tell application "Finder" set current view of front window to list view end tell tell application "System Events" tell application process "Finder" tell outline 1 of scroll area 2 of splitter group 1 of front window --(*1) vに取りうる値は下記文にて表示。 --value of attribute "AXIdentifier" of every column repeat with x from 1 to (count of column) tell column x set v to value of attribute "AXIdentifier" set newW to my getW(v) if newW is not 0 then set {w, h} to size set size to {newW, h} end if end tell end repeat end tell end tell end tell 0181名称未設定2014/04/01(火) 01:58:03.39ID:ynLRXj0p0>>180 ありがとうございます!バッチリでした! でも、なぜ記載されていない項目をコントロール出来るのか、 後学のためにも概略でいいので解説いただけませんでしょうか。 ふしぎでしょうがないです。 0182名称未設定2014/04/15(火) 17:50:21.49ID:SZkyhnNr0 OS X (10.9.2)のターミナルからosascriptで動かそうとしているんですが、 以下のパターン1と2では execution error: CotEditor got an error: Can’t get contents of selection of document 1. (-1728) というエラーがでてしまいます。 パターン3だと上手く動くのですが、 パターン1と2でエラーになってしまう理由はなんなのでしょうか? 最終的にはパターン1の形で動かそうとしています。
【パターン1:エラー】 #!/usr/bin/osascript set activeApp to path to frontmost application as text tell application activeApp set note_text to contents of selection of front document end tell return note_text
【パターン2:エラー】 #!/usr/bin/osascript set activeApp to "Macintosh HD:Applications:MustApp:CotEditor.app:" tell application activeApp set note_text to contents of selection of front document end tell return note_text
【パターン3:成功】 #!/usr/bin/osascript tell application "Macintosh HD:Applications:MustApp:CotEditor.app:" set note_text to contents of selection of front document end tell return note_text 0183名称未設定2014/04/15(火) 18:37:52.52ID:fqFcyd/l0>>182 文字列リテラルではない、 tell application アプリケーションバンドルへのpath は、正式にはサポートしていないとしか見えないねえ
frontmost applicationにはなら tell application "System Events" to set activeApp to name of application processes whose frontmost is true tell application activeApp でいいんじゃないの 0184名称未設定2014/04/15(火) 18:43:07.83ID:fqFcyd/l0>>183 × tell application "System Events" to set activeApp to name of application processes whose frontmost is true ○ tell application "System Events" to set activeApp to item 1 of (get name of application processes whose frontmost is true) 0185名称未設定2014/04/15(火) 19:17:18.30ID:SZkyhnNr0>>184 早速ありがとうございます。 >>184でもダメでした。 set activeApp to "CotEditor" もダメで、変数を使うと全てアウトのようです。 一応class of activeAppでパターン1と2の型を調べてみましたがtextでした。 0186名称未設定2014/04/15(火) 20:04:50.33ID:fqFcyd/l0>>185 ちなみにTerminalでやれば tell application "System Events" to set activeApp to name of application processes whose frontmost is true は、Terminalだよ。前のdelay入れて、その間にCotEditorを表にしてってしてるんだよね? 0187名称未設定2014/04/15(火) 20:07:12.17ID:fqFcyd/l0>>186 ×前にdelay入れて ○前のdelay入れて
【パターン1、改】 #!/bin/sh activeApp="` osascript - <<EOS1 set activeApp to path to frontmost application as text EOS1 `" osascript - <<EOS2 tell application "$activeApp" set note_text to contents of selection of front document end tell return note_text EOS2
【パターン2、改】 #!/usr/bin/osascript set activeApp to "CotEditor" using terms from application "CotEditor" tell application activeApp set note_text to contents of selection of front document end tell return note_text end using terms from 0191名称未設定2014/04/15(火) 23:48:23.27ID:SZkyhnNr0>>189 activeAppを使いたい理由はこんな形を想定していたからです。 tell application activeApp if activeApp = "CotEditor" then else if activeApp = "TextMate" then else end if end tell
とりあえずは、ifを外側にもってくれば動きそうです。 if activeApp = "CotEditor" then tell application "CotEditor" end tell else if activeApp = "TextMate" then tell application "TextMate" end tell end if