• 締切済み

applescript スクリプトエディタとアプリケーションで実行結果が異なる

クリップボードの文字列を検索置換しようとしています。 \\hoge\hogehoge→/Volumes/hogehogeのように。 ソースは下記なんですが、スクリプトエディタ上で実行すると 期待された結果が返ってくるのですが、アプリケーションとして 保存し、デスクトップからアプリケーションを実行すると 置換二つ目が処理されず、なぜか置換一つ目しか処理されません。 どのようにしたらよいでしょうか。 set theText to get the clipboard set backslash to ASCII character 128 set searchWd to backslash if (offset in theText of searchWd) = 0 then else set theText to my replaceTxt(theText, backslash, "/") --置換一つ目 set theText to my replaceTxt(theText, "//hoge", "/Volumes") --置換二つ目 display dialog theText end if on replaceTxt(myText, searchTxt, replaceTxt) set oldDel to AppleScript's text item delimiters set AppleScript's text item delimiters to searchTxt set myText to every text item of myText set AppleScript's text item delimiters to replaceTxt set myText to myText as string set AppleScript's text item delimiters to oldDel return myText end replaceTxt

みんなの回答

  • kapura
  • ベストアンサー率50% (48/95)
回答No.1

スクリプトエディタでは実行できているようですし、基本的にプログラムには問題ないと思います。既にやられているかもしれませんが、例えば1つ目の置換後にtheTextがどうなっているのか見てみれば、処理の違いがわかって対策も取れるのではないでしょうか (実行結果が異なる謎は別として問題は解決する)。 日本語環境や文字コードの微妙な問題とか、Mac OS X 10.5 Leopardで実行していてAppleScriptの仕様か何か変わったのが影響しているような気もしますが、私にはよくわかりません # AppleScriptの質問は詳しい方がいるApple Discussionsやメーリングリスト等に質問した方がより適確な回答が得られる気がします Mac OS X Technologies > AppleScript http://discussions.info.apple.co.jp/ http://discussions.apple.com/forum.jspa?forumID=724

参考URL:
http://d.hatena.ne.jp/E-WA/20060210/1139554011

関連するQ&A

  • AppleScriptファイルの読み書きについて

    Applescriptを始めたばかりの初心者です。 テキストファイルを読み込んで、検索置換を行うスクリプトを作成してます。 検索置換まではなんとかできたのですが、ファイルを同じ場所に同じ名前で上書きしたいのですが、うまくいきません。見よう見まねで作成しているので、エラーがでても対処できませんでした。 どうかアドバイスをお願いします。 set thefile to "■■HD:0000:0000.txt"--いつも同じファイルを読み込む try set fn to open for access file thefile with write permission set mystr to read fn -- 全ての内容を得る end try display dialog mystr--内容の確認 set mystr to my replaceAll(mystr, "▼", return) display dialog mystr--内容の確認 write mystr to fn close access fn on replaceAll(motoStr, findStr, repStr) set OriginalDelimiters to AppleScript's text item delimiters set AppleScript's text item delimiters to {findStr} set motoStr to text items of motoStr set AppleScript's text item delimiters to {repStr} set motoStr to motoStr as string set AppleScript's text item delimiters to OriginalDelimiters return motoStr end replaceAll

  • AppleScriptでpathを取得

    クリックしたファイルの絶対パスをクリップボードに保存する AppleScript(以下に記載)があるのですが、これでは クリップボードの中身が '/Users/ABC/Desktop/tmp1.jpg' '/Users/ABC/Desktop/tmp2.jpg' となります。 クオーテーション「 ' 」なしで、クリップボードに保存したいのですが どのようにすれば良いのでしょうか。 rest of characters of などを使ってどうにか組もうとしたのですが 初心者にはできませんでした。 どなたか、よろしくお願いします。 tell application "Finder" set theItems to "__OBJ_PATH__" set theResult to "" set old_delims to AppleScript's text item delimiters set AppleScript's text item delimiters to ":" set max to count of (every text item of theItems) repeat with num from 1 to max set theResult to theResult & quoted form of (text item num of theItems) if max > 1 and num < max then set theResult to "theResult" & " " end if end repeat set AppleScript's text item delimiters to old_delims set the clipboard to theResult end tell

  • AppleScriptでiCalを動かしてみたが

    以前に下記のようなAppleScriptがネット上に有りましたが(1999年12月28日) ----------------------------------------------実行 set dSta to my date "2013年6月4日火曜日 0:00:00" set dEnd to my date "2013年6月4日火曜日 16:00:00" -- 検索するカレンダー名 set calName to "仕事" -- 結果を格納する変数 set copyText to "" tell application "Calendar" set theList to every event of calendar calName whose (start date ≥ dSta) and (end date ≤ dEnd) repeat with x in theList set aDate to (start date of x) set copyText to copyText & (aDate as text) & tab & summary of x & (ASCII character 10) end repeat end tell -- 結果をクリップボードにコピー set copyText2 to my Sortsc(copyText) set the clipboard to copyText2 on Sortsc(aData) do shell script "echo " & quoted form of aData & " | sort -d" end Sortsc ------------------------------------------------------------- 今回これを利用したい思い osx10.8 applescript エディタ2.5.1にて起動してみようとしましたが下記のような不思議な現象がでました。 set dSta to my date "2013年6月4日火曜日 0:00:00" set dEnd to my date "2013年6月4日火曜日 16:00:00" としていますが date "1999年12月28日火曜日 0:00:00" and end date ≤ date "1999年12月28日火曜日 16:00:00" となってしまった。 なぜそうなったのかが分かりません。 どなたかご存知のお方がおられましたらご教授いただきたいのですが。 -----------------------------------返された値 tell application "Calendar" get every event of calendar "仕事" whose start date ≥ date "1999年12月28日火曜日 0:00:00" and end date ≤ date "1999年12月28日火曜日 16:00:00" --> {} end tell tell current application do shell script "echo '' | sort -d" --> "" end tell tell application "AppleScript Editor" set the clipboard to "" end tell ------------------------------------------------------------- 因にosx10.6 AppleScript2.3にはきちんと返された値は内容が取得されています。

    • ベストアンサー
    • Mac
  • AppleScriptがエラーになる

    osx10.8.4  AppleScriptエディタ2.5.1 にて以下の内容でFileMaker11へテキストデータを貼付けようとしましたところ ----------------------- set dbName to "test.fp7" tell application "FileMaker Pro Advanced" activate tell database dbName set contents of field "myText" to "ABC" end tell end tell ----------------------- error "FileMaker Pro Advanced でエラーが起きました:オブジェクトが見つかりません。 ----------------------- とのエラーが出ました。 ちなみにosx10.6.8 AppleScriptエディタ2.3ではテキストは読み込まれます。 osx10.8.4 の仕様が変わったのでしょうか 2・3日前にosのバージョンアップをしましたがそれが関係していたのでしょうか。 どなたかご存知の方がおられましたらご教授下さい。

    • ベストアンサー
    • Mac
  • AppleScriptで教えて欲しいです。

    現在、clipboardと同じ名前のフォルダー1つ(例:ABC123)のみ処理する。 →これを、clipboardの名前を含むフォルダー1つ(例:ABC123.4)のみ処理する。 に変更したいです。 ちなみにclipboardの名前を含むフォルダーは、1つしか存在しません。 申し訳ありませんが、実際の業務で使用している下記のスクリプト(無駄な部分も多少あるかと思いますが)を出来る限り変更を加えず、可能でしょうか? 無理であれば、大幅変更も可能ですので、ご教授の程、宜しくお願い致します。 global Num global fp set Num to the clipboard tell application "Finder" my shikyuseihan2data() --支給製版2課データ try duplicate fp to folder "data" of disk "HD" move fp to folder "jus:5)製版行き: 2課使用済" end try end tell --アクセス権 tell application "Terminal" activate do script with command "chmod -R 775 /Volumes/HD/data" quit end tell --支給製版2課のデータ on shikyuseihan2data() tell application "Finder" set x to name of every disk if "jus" is in x then else mount volume "afp://10.1.30.10/jus/" end if try set fp to "jus:5)製版行き:" & Num & ":" as text set fp to fp as alias end try end tell end shikyuseihan2data

    • ベストアンサー
    • Mac
  • メール受信日時をFileMakerへ記録したい

    前回メールの受信日をAppleScriptで取得する事を教わりました。ありがとうございました。 今回FileMakerの受信日フィールドへコピーしたくご教授賜りたく存じます。 ki073さんから以下のAppleScriptを教えて頂きした。 tell application "Mail" set theMessages to selection date received of first item of theMessages end tell で、Dateを取得できまたのでこれをFileMakerへ取り入れる為に tell application "Mail" set theMessages to selection set myText to date received of first item of theMessages end tell tell application "FileMaker Pro Advanced" activate tell current record of window 1 set contents of field "受信年月日" to my string (myText) end tell end tell としましたがエラーメッセージが出ました。 error "string (date \"2013年5月29日水曜日 5:34:02\") を取り出すことはできません。" number -1728 from string (date "2013年5月29日水曜日 5:34:02") どなたかご存知の方がおりましたらお願い致します。

  • AppleScriptで

    AppleScriptで jとgはtext変数、 iはinteger変数なんですが、 gのi単語目をjのi単語目に書き換えたいのですが set word i of g to word i of j で行うとエラーになります。 どうすれbくぁいいのでしょうか。

    • 締切済み
    • Mac
  • AppleScript 振り分けしたい

    set myText to unread count of mailbox "選択" of application "Mail" として "選択"ボックスに未読があるのでそのボックスをオープンしたいのだが if myText=1 then 選択ボックスを開き、処理したい。 end if 行き詰まってしまいました。 open~でもopen aliasでも開かずopen documentでも開きません エラー連発です。 メールの開き方ってどうしたら開く事ができるのでしょうか。どなたかお力をくださいませ。

  • AppleScript、変数名の中に変数

    AppleScriptを少しかじっただけで他の言語にうとい素人です。 repeat with i from 1 to 2 set aData(i) to... end repeat これでaData1とaData2という変数が作れたり呼び出せたりしたら便利だと思うのですが、 試してみたところできませんでした。 AppleScriptでも、特別な宣言などをすれば可能なのでしょうか? また、できたらで結構ですが、他の言語ならできる、という情報もあれば教えて下さい。 手抜きせず、リストに格納してやるのが王道ってことでしょうか? ^-^;

  • indesignでのapplescript

    はじめまして、indesign CS3で使用するapplescriptに関しての質問です。 自動で出力をしてくれるスクリプトを作りたいと思い、やってみたのですがうまくいきません。 色々調べて作ってみたのがこれです。 tell application "Finder" set filesInFolder to files in (choose folder) repeat with theFile in filesInFolder if name extension of theFile is "indd" then -- 拡張子を指定 set priset to "B4" -- プリントプリセットを指定 tell application "Adobe InDesign CS3" activate open theFile tell document 1 print using priset without print dialog close saving no end tell end tell end if end repeat end tell ここまではなんとかできたのですが、現段階では1階層下までのinddドキュメントしか読取ってくれません。 1見開きごとにパッケージしてできた子フォルダを一つの親フォルダにまとめることが多いので、フォルダ▶フォルダ▶.inddになります。 これでは親フォルダを指定したときに2階層下の子フォルダに分かれて入っている複数の.inddを一気に出力することができません。 何か解決策はありませんでしょうか? また、現段階に関してのご指摘もございましたらよろしくお願いします。

専門家に質問してみよう