.numbers
文書を.csv
文書に変換するスクリプトを作成しようとしています。それはコマンドラインから実行可能である必要がありますので、私はgitフックをpre-commitで使用できます。AppleScriptにファイルを保存する権限がありません
数字ファイルへのパスを取得してCSV形式でエクスポートするAppleScriptを書いていますが、「あなたには権限がありません(6)」ため実際のエクスポートは機能しません。私はこれがサンドボックスと関係があると考えていますが、AppleScriptを使用してファイルピッカーをポップアップすることはできません。これは完全に自動化する必要があるためです。
このファイルにエクスポートするAppleScriptのアクセス許可を与えるにはどうすればよいですか?
on run argv
set input_file to item 1 of argv
set output_file to input_file
--strip off the .numbers extention
set delims to AppleScript's text item delimiters
set AppleScript's text item delimiters to "."
if output_file contains "." then set output_file to (text items 1 thru -2 of output_file) as text
-- set the extension to be csv
set output_file to output_file & ".csv"
set output_file to POSIX file output_file
tell application "Numbers"
activate
tell (open input_file)
set activeDocument to it
with timeout of 3 seconds
export activeDocument as CSV to output_file
end timeout
close activeDocument saving yes
end tell
end tell
end run
完全なエラーメッセージは、私の呼び出しは、作業ディレクトリ/Users/me/
からosascript export_numbers_to_csv.scpt /Users/me/Test\ Scripts/MyTests.numbers
ある export_numbers_to_csv.scpt:604:676: execution error: Numbers got an error: The document “DisplayPlusButtonTestScripts.numbers” could not be exported as “DisplayPlusButtonTestScripts”. You don’t have permission. (6)
です。
私はスクリプトに書き込むように要求しているディレクトリに書き込む権限を持っています。また、(path to temporary items from user domain
経由で)一時ディレクトリにエクスポートしようとしましたが、同じエラーメッセージが表示されました。
AppleScriptクラスが 'input_file'とは何ですか?エラーは、宛先パスの構成に関連している可能性があります。 – vadian
@vadian私はそれが単なる文字列だと思う。コマンドラインからスラッシュを含むパス文字列として渡されます。 – MattL
なぜ私は、宛先のファイル拡張子がエラーメッセージに記載されていないのだろうかと思います。とにかく 'set output_file to POSIX file output_file to text'を試してください – vadian