set anAliasA to "/Users/***/Desktop/AppleScript/2015-02-16.numbers" --ファイルを開く set anAliasB to "Macintosh HD:Users:***:Desktop:AppleScript:makecsv:" & date string of (current date) & ".csv" --書き出す場所は固定+日付指定した+拡張子設定
tell application "Numbers" open anAliasA export document 1 to anAliasB as CSV --NumbersファイルをCSVで書き出し close document 1 end tell
書き出したい場所も、毎回同じファルダ内に書き出したいので、 set anAliasB to "Macintosh HD:Users:***:Desktop:AppleScript:makecsv:" & date string of (current date) & ".csv"
で指定しているのですが、下記のエラーが出ます。 error "Numbers でエラーが起きました:書類“2015-02-16.numbers”を“2015年2月18日水曜日”として書き出せませんでした。アクセス権がありません。" number 6
書きだしたファイル名はユニーク名で付けたいのでとりあえず今はdate string of (current date) で指定してます、本当は時間もファイル名に入れたい。
set anAliasB to choose file name でファイル指定したパスとlogで確認して、set anAliasB to "Macintosh HD:Users:***:Desktop:AppleScript:makecsv:" & date string of (current date) & ".csv" にしてみたのですが・・・。
FileMaker Proで表示中のレコードのデータ内容をCSV書き出し http://piyocast.com/as/archives/16720461名称未設定2015/02/18(水) 17:28:14.34ID:nxmMCsB60>>460 set anAliasB to POSIX file (“/Users/***/Desktop/AppleScript/makecsv/“ & date string of (current date) & “.csv”)
(「ご質問お願いします」は違うよ。本来どうでもいいwが2度目なのでいちおう) 0462名称未設定2015/02/18(水) 19:15:37.54ID:nxmMCsB60>>460 >本当は時間もファイル名に入れたい set currentDate to current date set anAliasB to POSIX file (“/Users/***/Desktop/AppleScript/makecsv/“ & date string of currentDate & “ “ & time string of currentDate & “.csv”)
としたいところだが、”/“や”:”がファイル名に入るのは好ましくないので、
set dateTimeString to do shell script "date +'%Y-%m-%d %H-%M-%S'" set anAliasB to POSIX file (“/Users/***/Desktop/AppleScript/makecsv/“ & dateTimeString & “.csv”)
AppleScriptで do shell script "zip text.zip -r ./x/" を実行するとエラーがですます。
エラー内容 error " zip warning: name not matched: ./x/ zip error: Nothing to do! (try: zip -r text.zip . -i ./x/)" number 12 0467名称未設定2015/02/26(木) 12:46:07.99ID:kGBOUlNz0 do shell script "pwd" してみ カレントディレクトリが / になってるから >>1のTN2065: do shell scriptざっと調べた方がええよん 絶対パスでやるか、同じ do shell script 内で cd するか
Terminal echo 'どうして北海道(ほっかいどう)で酪農(らくのう)が広(ひろ)まったのかな。' | sed -e 's/([^)]*)//g' 結果>>どうして北海道で酪農が広まったのかな。
do shell script do shell script "echo 'どうして北海道(ほっかいどう)で酪農(らくのう)が広(ひろ)まったのかな。' | sed -e 's/([^)]*)//g'" 結果>>どうして北海道で酪農(らくのう)が広まったのかな。 0472名称未設定2015/03/02(月) 16:55:54.65ID:+sCo7k3t0 Terminalで「起動時にロケール環境変数を設定」にチェック入ってると LANG が設定されるようだから、これをdo shell scriptでも付けてやればとりあえず同じになったよ (英語環境だと LANG でなくて LC_CTYPE だった)
do shell script "export LANG=ja_JP.UTF-8; echo 'どうして北海道(ほっかいどう)で酪農(らくのう)が広(ひろ)まったのかな。' | sed -e 's/([^)]*)//g'" --> "どうして北海道で酪農が広まったのかな。" チェックを外したらTerminalでも>>471のdo shell scriptの結果と同じ 詳しいことは知らん 0473名称未設定2015/03/02(月) 17:27:48.52ID:+sCo7k3t0 こうかな
set inputFile to droppedItems repeat with theItem in inputFile tell application "Finder" set folderPath to parent of theItem as text end tell display dialog folderPath end repeat 0504名称未設定2015/03/15(日) 14:39:45.90ID:AV7GXmsk0 dialog出ないって事はどこがでエラーになってるんだろうね dorpletだとエラーで即落ちするから
on application_openFiles_(sender, droppedItems) repeat with theItem in droppedItems set parentPath to theItem's stringByDeletingLastPathComponent() display dialog (parentPath as text) end repeat end application_openFiles_
>>504 >dialogが表示されず 何かの拍子にアプリケーションの作成が壊れる。MainMenu.nibがアプリケーションバンドルにコピーされない。直し方はまだわからんな Dropletだからいらんからいらんのだが、Dropletとしてちゃんとプロジェクト作成手順を踏まなければならないのかなあ 単に>>503のようなスクリプトでDroplet作るなら、AppleScript Editorでの方がいいかもしれない 0507名称未設定2015/03/15(日) 15:38:41.87ID:VmwaxW7K0>>506 ×>>504 ○>>503 すまんす 0508名称未設定2015/03/15(日) 16:02:30.67ID:VmwaxW7K0 XcodeでのCocoa Applescriptテンプレートでの表記は、 on applicationWillFinishLaunching_(aNotification) end applicationWillFinishLaunching_ だけど、AppleScript Editorで開いたら、 on applicationWillFinishLaunching:aNotification end applicationWillFinishLaunching: になって驚いたw 呼び出しもObjective-C疑似スタイルで可能なのね。Xcodeでも いつからなんだろ 0509名称未設定2015/03/15(日) 16:07:08.38ID:/RgW8kRq0>>503 tell application "Finder" set inputFile to droppedItems as alias list repeat with theItem in inputFile set folderPath to (parent of (theItem as alias)) as Unicode text display dialog folderPath as Unicode text end repeat end tell
set myScript to "#coding: utf-8 str=\"こんにちは\" str2=ARGV[0] p str,str2 puts str2" do shell script "ruby -e " & quoted form of myScript & " " & quoted form of "こんにちは" 0517名称未設定2015/04/16(木) 11:29:38.57ID:JP8CNjtg0>>516 set myScript to "#coding: utf-8 \nstr=\"こんにちは\" \nstr2=ARGV[0] \np str,str2 \nputs str2" do shell script "ruby -Ku -e" & quoted form of myScript & " " & quoted form of "こんにちは" -Kオプションで文字コード指定すれば? しかしこのコードはこれで良いのか? 05185162015/04/16(木) 11:48:12.31ID:fNeO9YuQ0>>517 おーできました。 -Kuで。ありがとうございます。 #coding: utf-8を入れてあれば良いのかと思っていました。 0519名称未設定2015/05/08(金) 22:46:21.29ID:vR7cr5an0 これは、エラーにならない。
tell application "Finder" set tmp to POSIX file "/tmp" end tell
こうすると、実行時エラーになる。
tell application "Finder" set tmp1 to "/tmp" set tmp to POSIX file tmp1 end tell
なぜだか理由がわかりません。 ご教授お願いします。 0520名称未設定2015/05/09(土) 00:35:21.89ID:S1iniwej0 エラーになるならエラー内容も書かないと error "Finder でエラーが起きました:POSIX file ¥"/tmp¥" を取り出すことはできません。" number -1728 from file
-1728はMacErrors.hを見ると、 errAENoSuchObject = -1728, /* e.g.,: specifier asked for the 3rd, but there are only 2. Basically, this indicates a run-time resolution error. */ とある。「Finder でエラーが起きました」言うてるから
--tell application "Finder" set tmp1 to "/tmp" set tmp to POSIX file tmp1 --end tell
二番目の as POSIX file と言う表現は強制的な型変換処理で、これは実行時に処理される。 as による型変換は基本的に tellブロックの中でもスクリプト側で優先して処理されるので、 Finderが受け取る引数はファイルを示すオブジェクトになっていて正しく処理できる。
三番目のものは、一見ファイル参照表現のように見えるけど、変数の tmp1 になにが入るかは 実行時で無ければ分らないので、コンパイル時には処理できない。そして実行時に get POSIX file "/tmp" が Finder に丸投げされて、でも Finder は POSIX file をうまく扱えず エラーになる…はずが、なぜか exists の場合は false が帰ってきてしまう。 ちなみに System Events で同じことをするとちゃんと(?)「エラー -1728」になった。もちろん、 tellブロックの外でこの手の手順を記述するならスクリプト側で処理されるので、問題にはならない。 0525名称未設定2015/05/10(日) 11:56:58.29ID:ihNZ0FRq0 前にもここに書いたんだけど、Finderもfile classを定義してるからキーワードの解釈が 衝突してるんですよ。my付けてglobalな定義を優先すれば良い。 tell application "Finder" set tmp1 to "/tmp" set tmp to my POSIX file tmp1 end tell tell application "Finder" set tmp1 to "/tmp" exists my POSIX file tmp1 end tell 0526名称未設定2015/06/27(土) 20:35:43.04ID:oLuCxE430 display dialog "このスレって、生きてるんですよね?" 0527名称未設定2015/06/27(土) 20:54:57.43ID:XVP2cUyr0 もちろんさ 0528名称未設定2015/06/27(土) 20:58:32.57ID:2HcvqLl20 結果: {button returned:"OK"} 0529名称未設定2015/06/27(土) 23:59:13.55ID:IO5TRzBI0 error number -128 0530名称未設定2015/07/02(木) 00:53:17.64ID:JqmVzF680 YosemiteからAppleScriptの代わりに JavaScriptも使えるようになったのね。 今頃気が付いた。 0531名称未設定2015/07/02(木) 02:03:26.78ID:5ci7EMIH0 それでScript Editorになったのか。納得 0532名称未設定2015/07/02(木) 02:04:23.51ID:3sKDtNad0 Swiftも足せばいいのに 0533名称未設定2015/07/02(木) 14:04:43.02ID:P9q2kFwz0 xcodeぇ… 0534名称未設定2015/07/03(金) 20:28:58.67ID:BY+AkDuD0 いろんなサイトを見ながら見様見まねで finder上で選択したファイルを選択したフォルダにコピーするスクリプトに トライしてみたのですが 「if D_fileExist = "false" then」の部分がスルーされて「else display dialog ~」が実行されてしまいます。 ご指導いただけるとうれしいです。 よろしくお願いします。
tell application "Finder" set A_filePath to selection as alias list if A_filePath = {} then display dialog "ファイルが選択されていません" return end if end tell
getFileName(A_filePath)
on getFileName(theFile) set tmp to AppleScript's text item delimiters set AppleScript's text item delimiters to ":" set fileName to last text item of (theFile as string) set AppleScript's text item delimiters to tmp return fileName end getFileName 0535名称未設定2015/07/03(金) 21:30:06.17ID:xfqT0ASe0 質問文とコードが合ってないじゃないの 0536名称未設定2015/07/03(金) 21:43:28.53ID:zhZri2f80 文とスクリプトが一致してない(し、文のスクリプトが間違ってもいる)が、そのままでも意図したようには動いているけど
俺だったら set A_filePath to selection if (count of A_filePath) is 0 then って書くかなあ 0537名称未設定2015/07/03(金) 21:57:53.21ID:xcqVHBQg0>>534続きです。
set C_fileName to getFileName(A_filePath) set B_folderPath to (choose folder)
tell application "Finder" get exists of file C_fileName of B_folderPath set D_fileExist to result if D_fileExist = "false" then duplicate selection to B_folderPath without replacing else display dialog "すでに " & C_fileName & " は存在します。上書きしますか?" with icon caution set E_buttonResult to button returned of result if E_buttonResult = "OK" then duplicate selection to B_folderPath with replacing end if end if end tell> 0538名称未設定2015/07/03(金) 22:05:26.31ID:zhZri2f80 なるほどw exists of で得られるのは Boolean値 であって、文字列(の"false"/"true")じゃないよ if not D_fileExist then でとか 0539名称未設定2015/07/03(金) 22:45:13.35ID:xcqVHBQg0>>538 ありがとうございます! とりあえず動くようになりました。 Boolean値って何だ? と検索するぐらいの初心者で いろんなところからコピペして繋げてみた感じです。 なので試行錯誤している途中で これだとフォルダのコピーが出来ないことに気付きました。
Appleの開発者サイトを見ると "The JavaScript OSA component implements JavaScript for Automation. The component can be used from Script Editor, the global Script Menu, in the Run JavaScript Automator Action, applets/droplets, the osascript command-line tool, the NSUserScriptTask API, and everywhere else other OSA components, such as AppleScript, can be used." と書いてあるので、SafariのJavaScriptから直接実行するのは無理そうですね。 0550名称未設定2015/07/04(土) 23:29:23.28ID:gXTZwE1/0>>548 ・ウィンドウを何も表示してない ・アプリケーションを隠しておく ・起動してない 全部手前にくるなー