【パターン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
最終的に使い方はAutomatarのアプリケーションにして必要があればアプリをダブルクリックして瞬時に変更したいんです。 0244名称未設定2014/08/21(木) 16:19:28.01ID:eHJIQPJB0>>239 ProgressBar表示するappletとかOS9時代からあるけど、入れても結局ウザくて使わないな。 自分の用途ではscriptの終了や経過知りたい場合は音で十分。 do shell script "afplay /System/Library/Sounds/Hero.aiff" を最後に置いたり、音声で知らせたりする。 repeat with i from 10 to 90 by 10 say quote & i & "%" & quote end repeat say "done!" 0245名称未設定2014/08/21(木) 18:24:50.87ID:/YoxOgpZ0>>243 http://hints.macworld.com/article.php?story=20040908141042786 csreenがMavericksで動くのか試してないけど 0246名称未設定2014/08/21(木) 18:38:10.22ID:87bgOWlk0>>243 途中まで tell application "System Preferences" activate set current pane to pane "com.apple.preference.displays" end tell tell application "System Events" tell process "System Preferences" tell window 1 tell tab group 1 click radio button "Display" tell radio group 1 click radio button "Scaled" end tell tell scroll area 1 tell table 1 select row 2 end tell end tell end tell end tell end tell end tell 0247名称未設定2014/08/21(木) 18:47:50.56ID:DwsP4u890 お二人さんレスどうも。
where/whose句によるフィルターについて教えてください。 2や3のような事を実現するにはどのように書けばいいのでしょうか? グルグル回さずに済む方法が知りたいです。 0255名称未設定2014/08/26(火) 22:15:15.01ID:mMnMi0CT0 すまん適当だし合ってるかどうかも知りませんが iWork items (whose ((item 1 of position) as integer) of it > 100) of page 1 of document 1 item 1 of position とか参照が参照のままでダメだから、型を適当に明示して変換すると けっこう行けたり行けなかったりしないかなあ?
set theList to (find text "[+-]?\\d+(\\.\\d+)?" in "数字を足してね♥︎ -1, 0.01, +1, 2,..,99 " with regexp, all occurrences and string result) set total to 0 repeat with x in theList set total to (total + (atof (x))) end repeat set message to "(" & (join theList using ") + (") & ") = " & total
find text: これがあると正規表現まわりで rubyその他に頼る必要がなくなる atof: x as real と書いたのと同じになる (他にも sin, cos とかC言語ライクな数学関数が色々) join: 定石の set AppleScript's text item delimiters to "," を使ったリスト連結よりもシンプル マニュアル: http://www.satimage.fr/software/en/dictionaries/dict_satimage.html0268名称未設定2014/09/20(土) 07:21:55.77ID:J1L8Sc170 数値 + 数値文字列 = 数値 なので、この場合 atof は無くてもOKでした 0269名称未設定2014/09/20(土) 08:32:33.91ID:1d3efwqb0>>267 わかる人は使えばいいけど、正規表現、文字列の検索・置換などの取り扱いは ASのデフォルトの考え方を理解してないと、あとでつまづくし、機能拡張を インストールしないと使えないスクリプトは会社などで使うときとても面倒。 検索・置換程度の話なら避けたほうがいいと個人的には思う。 do shell scriptでrubyなりperlなりsedなりいろいろ使う契機にもなるし。 0270名称未設定2014/09/20(土) 08:35:19.68ID:3i170VB80>>269 同意 個人的にosaxは使わないようにしてる いまはdo shell scriptがあるから、何か複雑なことしたかったら パッケージにシェルスクリプト突っ込んだ方が早いし確実 0271名称未設定2014/09/20(土) 09:18:42.39ID:1d3efwqb0 「ASやってます」と言うと笑われるけど、その実、中身はdo shel scriptで他のおいしいところを 使いまくり、というのはよくある話。グルー言語としてのASは非常に強力。 0272名称未設定2014/09/20(土) 16:27:57.17ID:AqRjHw4B0 do shel scriptは便利だけど使い方間違えるとめちゃくちゃ遅くなるから、気をつけないとね。 たとえば大量に変換とかの場合は、do shel scriptを回すんじゃなくて do shel scriptの中で回るようにとかね。 0273名称未設定2014/09/20(土) 23:11:29.75ID:3i170VB80>>272 君はコンパイラに頼りすぎ >shel 0274名称未設定2014/09/20(土) 23:55:25.38ID:AqRjHw4B0>>273 なんも考えずに上のコピペしただけだわ 0275名称未設定2014/10/25(土) 07:12:00.39ID:5qSeWYWr0 けっこうびっくりしたけど、10.10からのJavaScriptもここでやるといいよね。 ほかでやるとこないし。ほぼなんでもできるのかな? 0276名称未設定2014/10/25(土) 09:21:10.13ID:5qSeWYWr0 思いつきだけだけど、JavaScriptだけでGUIつきアプリとかできるの? できるわけないか。 0277名称未設定2014/10/25(土) 14:50:07.62ID:LnSjrQfx0 Macでプログラミング{10} http://anago.2ch.net/test/read.cgi/mac/1248682344/0278名称未設定2014/10/25(土) 17:55:17.74ID:N9eHGFRP0 質問です。OS Mavericks アップルスクリプトでもう少しGUIのいいものを作ろうとして Xcode6.1をつかってcocoa-applescriptのアプリケーションを触ってみようと思いました。 具体的にはGUIのdatePickerを配置して AppDelegate.applescriptのファイルで ユーザーがdatePickerで設定した日付を取得しようとしたのです。 下にコメントアウトしてるところがdatePickerとつながっており取得できていない箇所です。
on workSchedulRecorder_(sender)
set Client to name_Client's stringValue() as string -- set the_Date to int_date's dateValue()
end workSchedulRecorder_
上のはCombo BoxとつながっておりstringValue() as stringで取得できました。 問題の箇所は調べて見つかったのに下のようなエラーがでました
2014-10-25 17:52:08.866 DPC Client Scheduler[2711:303] *** -[AppDelegate workSchedulRecorder:]: Can’t make &#171;class ocid&#187; id &#171;data optr000000000D0000007491B841&#187; into type Unicode text. (error -1700)
dateValue()ではなく違う言葉なのでしょうか・・・ どなたかお力になってくださいませんでしょうか 0279名称未設定2014/10/25(土) 18:45:32.40ID:Y7ywkFMP0>>278 set the_Date to int_date's dateValue() これでそのエラーになる?出ないけどなあ set the_Date to int_date's dateValue() as string だと、文字列に変換できないオブジェクト(この場合NSDate)を文字列に変換しようとすると(全く)同じエラーが出るけど
そこで、もう一つ質問したいのですが、 このthe_Dateから得たdate_Value()を アップルスクリプトのdateの型?っていうのでしょうか date "2014年10月25日土曜日 0:00:00" にするのにはどうすればいいのでしょうか? 0281名称未設定2014/10/25(土) 19:25:35.38ID:Y7ywkFMP0>>279,278 とりあえずな日付(NSDate)を文字列にはこんなんかな set theDate to int_date's dateValue() set dateFormatter to current application's NSDateFormatter's alloc()'s init()'s autorelease() dateFormatter's setDateFormat_("YYYY-MM-dd hh:mm:ss a") set dateString to dateFormatter's stringForObjectValue_(theDate)
>>280 わからんw 文字列にしたら date にできるんじゃないかな。AppleScriptもdate<->文字列はめんどくさいっぽいなあ 0282名称未設定2014/10/25(土) 19:27:59.17ID:pbKxf6+40 暇つぶしにデータピッカからテキストにして、テキストからNSDateに変換する流れ書いてみた、テストしてないです。 NSDateはテキストじゃないから、直接変換しようとしてつまるよねー。 property datePicker : missing value set pickDate to my datePicker's dateValue() set nsDateObj to my pick2date(pickDate)
on pick2date(pickdate) set cal to current application's class "NSCalendar"'s currentCalendar() set com to cal's components_fromDate_(254, pickdate) set year to com's |year|() set month to com's |month|() set day to com's |day|() set hour to com's hour() set minute to com's minute() set second to com's |second|() set time2sec to (((hour) * 3600) + ((minute) * 60)+ second) as number set qqq to my mkDate(year, month, day, 0) + time2sec return result end pick2date
on makeDate(y, m, d, s) tell (get current date) set {year, its month, day, time} to {y, m, d, s} return its contents end tell end makeDate 0283名称未設定2014/10/25(土) 19:30:07.23ID:pbKxf6+40>>282 あNSDateじゃなくてASDate 0284名称未設定2014/10/25(土) 20:10:23.39ID:pbKxf6+40 ハンドラの呼び出し名適当なやつのまんまだわ適宜直してちょ 0285質問者 2782014/10/25(土) 20:18:04.97ID:N9eHGFRP0 281さんありがとうございます。実際おしえてもらったコードを入れてみました set Client to name_Client's stringValue() as string set the_Date to int_date's dateValue()
set dateFormatter to current application's NSDateFormatter's alloc()'s init()'s autorelease() dateFormatter's setDateFormat_("YYYY-MM-dd hh:mm:ss a") set dateString to dateFormatter's stringForObjectValue_(theDate) 最後の行でエラーが起きてしまいました Scheduler[3049:303] *** -[AppDelegate workSchedulRecorder:]: The variable theDate is not defined. (error -2753) ご返答のコード内容が理解できない初心者なのですが 変数のthe_Dateは作っていただいた書式にははまらないということでしょうか もう少しねばってみたいと思います。ご返答ありがとうございました! 0286名称未設定2014/10/25(土) 20:26:21.21ID:pbKxf6+40>>285 落ち着きなさいtheDateが無いんだ 君はthe_Dateにしてるみたいだよ。 0287質問者 2782014/10/25(土) 20:55:41.66ID:N9eHGFRP0 285さんありがとうございます!! もう、学も無いのに英語サイトまわってくたくたになっていました。笑 出ました出ました! 本当に助かりました。ありがとうございます! dateformatについての基礎知識は明日にでも探してみたいと思います。 これで、やりたいことが出来そうです。