2ちゃんねる スマホ用 ■掲示板に戻る■ 全部 1- 最新50    

■ このスレッドは過去ログ倉庫に格納されています

AppleScript アップルスクリプト 質問、発表 6

1 :名称未設定:2013/12/21(土) 21:50:45.07 ID:1PJJFexL0.net
質問、発表どっちでもスレ。

■注意
安直なスクリプト作成依頼、丸投げ、「こういうの作ってください!」はお断り。
わからない点、エラーが解決できない点についてはスクリプト片を添えて質問すること。
OSバージョンも忘れずに。

■参考
AppleScript Language Guide
https://developer.apple.com/library/mac/documentation/AppleScript/Conceptual/AppleScriptLangGuide/
TN2065: do shell script
https://developer.apple.com/library/mac/technotes/tn2065/
AppleScript: The Language of Automation
http://www.macosxautomation.com/applescript/
MacWiki - AppleScript
http://macwiki.sourceforge.jp/wiki/index.php/AppleScript
鳶嶋工房 / AppleScript
http://tonbi.jp/AppleScript/
AS Hole(AppleScriptの穴)
http://piyocast.com/as/
■過去スレ
1 http://pc11.2ch.net/test/read.cgi/mac/1174045850/
2 http://pc11.2ch.net/test/read.cgi/mac/1197443062/
3 http://pc11.2ch.net/test/read.cgi/mac/1223026902/
4 http://anago.2ch.net/test/read.cgi/mac/1256127156/
5 http://anago.2ch.net/test/read.cgi/mac/1330350325/

181 :名称未設定:2014/04/01(火) 01:58:03.39 ID:ynLRXj0p0.net
>>180
ありがとうございます!バッチリでした!
でも、なぜ記載されていない項目をコントロール出来るのか、
後学のためにも概略でいいので解説いただけませんでしょうか。
ふしぎでしょうがないです。

182 :名称未設定:2014/04/15(火) 18:37:52.52 ID:fqFcyd/l0.net
>>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
でいいんじゃないの

183 :名称未設定:2014/04/15(火) 18:43:07.83 ID:fqFcyd/l0.net
>>182
×
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)

184 :名称未設定:2014/04/15(火) 19:17:18.30 ID:SZkyhnNr0.net
>>183
早速ありがとうございます。
>>183でもダメでした。
set activeApp to "CotEditor"
もダメで、変数を使うと全てアウトのようです。
一応class of activeAppでパターン1と2の型を調べてみましたがtextでした。

185 :名称未設定:2014/04/15(火) 20:04:50.33 ID:fqFcyd/l0.net
>>184
ちなみにTerminalでやれば
tell application "System Events" to set activeApp to name of application processes whose frontmost is true
は、Terminalだよ。前のdelay入れて、その間にCotEditorを表にしてってしてるんだよね?

186 :名称未設定:2014/04/15(火) 20:07:12.17 ID:fqFcyd/l0.net
>>185
×前にdelay入れて
○前のdelay入れて

ああ、
set activeApp to "CotEditor"
もダメなのか。んー、そうだっけ

187 :名称未設定:2014/04/15(火) 20:12:34.56 ID:SZkyhnNr0.net
>>185
説明してませんでしたが、
TotalTerminalを使って
Terminalを呼び出してもactivateしないようにしています

188 :名称未設定:2014/04/15(火) 22:31:26.66 ID:fqFcyd/l0.net
>>187
どうもCotEditor側の問題のような
documentのプロパティのアクセスで、Text Suiteにはアクセスできるが、CotEditor suiteにはことごとく失敗する
なんで application リテラルと変数 で、CotEditor内の処理に関係するのかわからんけど

contents of selection は CotEditor 独自なんだよね?
telll application "CotEditor"
で、いいんでないの?

189 :名称未設定:2014/04/15(火) 23:01:57.14 ID:WdFslrQw0.net
この形でもよければ(うちは10.8.5だけど)

【パターン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

190 :名称未設定:2014/04/15(火) 23:48:23.27 ID:SZkyhnNr0.net
>>188
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

>>189
ありがとうございます。
勉強になりました。
もう少し試行錯誤してみようと思います。

総レス数 1008
389 KB
新着レスの表示

掲示板に戻る 全部 前100 次100 最新50
read.cgi ver 2014.07.20.01.SC 2014/07/20 D ★