我正在尝试编写一个将.numbers
文档转换为.csv
文档的脚本。它需要可以从命令行执行,以便我可以在预提交 git 挂钩中使用它。
我编写了一个 AppleScript 来获取数字文件的路径并将其导出为 CSV,但实际导出将无法正常工作,因为“您没有权限。(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
完整的错误信息是
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)
我的调用osascript export_numbers_to_csv.scpt /Users/me/Test\ Scripts/MyTests.numbers
来自工作目录/Users/me/
。
我确实有权写入我要求脚本写入的目录。我还尝试导出到临时目录(通过path to temporary items from user domain
),但得到了相同的错误消息。