サーバー側 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
(続く) 0210名称未設定2014/05/29(木) 20:00:20.21ID:8Urv7sLM0 再現スクリプト on run my setWake() my putNotification() end run on wake:aNotification NSLog("%@", "wake_") end wake: on setWake() tell my NSWorkspace's sharedWorkspace()'s notificationCenter() addObserver_selector_name_object_(me, "wake:", "NSWorkspaceDidWakeNotification", missing value) end tell end setWake on putNotification() set uNotification to my NSUserNotification's alloc()'s init() tell uNotification setTitle_("Title") setSubtitle_("Subtitle") end tell tell my NSUserNotificationCenter's defaultUserNotificationCenter() setDelegate_(me) deliverNotification_(uNotification) end tell end putNotification on userNotificationCenter:aCenter didActivateNotification:aNotification NSLog("%@", "activate") end userNotificationCenter:didActivateNotification:
参照ページ ttp://macscripter.net/viewtopic.php?id=42087 参照スクリプト ttp://macosxautomation.com/lion/applescript.html の Applet with Progress Window
再現スクリプトを下記のように分割し、修正します main.scptの内容 on run set mySubScpt to my subScpt's alloc()'s init() tell mySubScpt setWake() putNotification() end tell end run (続く) 0213名称未設定2014/05/30(金) 16:42:24.82ID:w2GSLBfm0 sub.scptの内容(CocoaAppletAppDelegate.scptと同じ階層に置きます) script subScpt on wake:aNotification NSLog("%@", "wake_") end wake: on setWake() tell my NSWorkspace's sharedWorkspace()'s notificationCenter() addObserver_selector_name_object_(me, "wake:", "NSWorkspaceDidWakeNotification", missing value) end tell end setWake on putNotification() set uNotification to my NSUserNotification's alloc()'s init() tell uNotification setTitle_("Title") setSubtitle_("Subtitle") end tell tell my NSUserNotificationCenter's defaultUserNotificationCenter() setDelegate_(me) deliverNotification_(uNotification) end tell end putNotification on userNotificationCenter:aCenter didActivateNotification:aNotification NSLog("%@", "activate") end userNotificationCenter:didActivateNotification: on NSLog(fmg, msg) do shell script "syslog -s -l Notice " & msg end NSLog end script
on run {input, parameters} tell application "Safari" make new document with properties {URL:"hoge"} (省略) do JavaScript "document.getElementsByName('text')[0].value = '" & input & "'" in document 1 end tell return input 0222名称未設定2014/06/14(土) 08:54:27.08ID:BqgujY2d0>>221 文字列が途中で分断(改行)されるから、JavaScript文法エラーになるんじゃね 改行毎の文字列に分けてJavascriptで結合するとか、URLエスケープとかで1行にしてJavascriptで戻すとかかなあ
set urlEncodedInput do shell script "/usr/bin/php -r 'echo trim(urlencode(" & "¥"" & quoted form of input & "" & "¥"));'" do JavaScript "document.getElementsByName('text')[0].value = decodeURIComponent( '" & urlEncodedInput & "');" in document 1 なんて 0223名称未設定2014/06/14(土) 18:25:41.63ID:6HYvVvD80>>220 そういう意味合いではObj-Cと大差無いよーな? 0224名称未設定2014/06/14(土) 20:01:40.28ID:ZFqWjo7C0>>223 多分IBのbindingとかのこと言ってるんだろうけど、扱えないって言ってるから、そんな言えないけどさ 全部コードで出来るのにな。てかswiftもbindingって意味ならマウスでドラッグして線繋ぐ所は、同じなのに... 0225名称未設定2014/06/30(月) 00:54:26.49ID:IeiIh5C50 特定のデスクトップを指定して、ウィンドウを再配置することは可能でしょうか?
デスクトップというのは、トラックパッドを3本指か4本指左右スワイプできりかえるものです。
Macbook Air を外部ディスプレイにつないだとき、 Air 本体のディスプレイのデスクトップ1 にクローム、 Air 本体のディスプレイのデスクトップ2にファインダー2つ、 外部ディスプレイのデスクトップ3 にテキストエディタ という風に適切なウィンドウリサイズで再配置したいのです。 0226名称未設定2014/07/03(木) 11:46:09.68ID:9XALmAAL0 何もしないアプリケーションをデスクトップの数だけ作って Dockで各デスクトップに割り当てておき それを実行した後で目的のアプリで新規ウィンドウを開けばいいんじゃないでしょうか 0227名称未設定2014/07/03(木) 12:57:14.43ID:Aqyg/V0F0 デスクトップの切り替えを試行(キーボードショートカットで ^1 ^2 が定義されているとき)
tell application "System Events" delay 1 key code 19 using control down -- switch to desktop 2 delay 1 key code 18 using control down -- switch to desktop 1 end tell 0228名称未設定2014/07/03(木) 16:31:10.31ID:AqXSO5JN0>>227 目からうろこです。 そのデスクトップ切り替えのショートカットあるの忘れてました。 スワイプでデスクトップ切り替えてたので、環境設定でこの切替ショートカットのチェックマーク外してました。 0229名称未設定2014/07/05(土) 12:12:19.68ID:YyTe2e2J0 ASは幸せでいいなあ。スクリプト書いてて楽しいもの。 0230名称未設定2014/07/15(火) 03:19:28.79ID:wYxshpyA0 選択範囲のテキストを (* *) で囲みたいのですがうまく行きません。
tell application "System Events"
set oriClip to the clipboard
keystroke "x" using {command down} set the clipboard to "(*" & (the clipboard) & "*)"
set copiedText to (the clipboard) set the clipboard to "(*" & copiedText & "*)"
log (the clipboard)
delay 0.5 keystroke "v" using {command down}
set the clipboard to oriClip
end tell 0233名称未設定2014/07/15(火) 09:36:24.47ID:GUZrA3CI0 Automatorでサービス、選択したテキストを入力にして
on run {input} set input to {"(*" & input & "*)"} as text return input end run
こういうのを登録して使ってる。 0234名称未設定2014/07/15(火) 14:07:44.75ID:gBz1a97Zi 何でか知らんが set the clipboard した後に keystroke でペーストすると更新前の内容 になっちまうけど、 run script か do shell script で迂回してやればいけそう あと keystroke してから実際にカットorペーストされるまで多少タイムラグがあるみたいなんで、次の処理が早すぎると上手くいかない
なのでこんなんとか
set oriClip to the clipboard tell application "System Events" keystroke "c" using command down do shell script "printf '(*%s*)' $(pbpaste) | pbcopy" keystroke "v" using command down end tell delay 0.5 set the clipboard to oriClip