Csv Applescript没有保存文件的权限
我正在尝试编写一个脚本,将Csv Applescript没有保存文件的权限,csv,applescript,iwork,apple-numbers,applescript-numbers,Csv,Applescript,Iwork,Apple Numbers,Applescript Numbers,我正在尝试编写一个脚本,将.number文档转换为.csv文档。它需要可以从命令行执行,这样我就可以在预提交git钩子中使用它 我已经写了一个AppleScript来获取一个数字文件的路径并将其导出为CSV,但是实际的导出将不起作用,因为“您没有权限。”。我认为这与沙箱有关,但我不能使用AppleScript弹出文件选择器,因为这需要完全自动化 如何授予AppleScript导出到此文件的权限 on run argv set input_file to item 1 of argv
.number
文档转换为.csv
文档。它需要可以从命令行执行,这样我就可以在预提交git钩子中使用它
我已经写了一个AppleScript来获取一个数字文件的路径并将其导出为CSV,但是实际的导出将不起作用,因为“您没有权限。”。我认为这与沙箱有关,但我不能使用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:执行错误:numbers获取错误:文档“DisplayPlusButtonTestScripts.numbers”无法导出为“DisplayPlusButtonTestScripts”。你没有权限。(6)
我的调用是从工作目录/Users/me/
将osascript导出到csv.scpt/Users/me/Test\Scripts/MyTests.numbers
我确实有权限写入我请求脚本写入的目录。我还尝试导出到临时目录(通过用户域中临时项目的
路径),但收到相同的错误消息 如果.csv文件已经存在于同一目录中,并且与您试图导出到的文件同名,则权限可能会变得混乱。如果您创建了该.csv文件或至少在某个时候编辑/打开了该文件,则您将有权导出到该名称,但如果以前从未在您的计算机上打开过该文件以进行写访问(例如,如果您下载了该文件),则不存在必要的权限
要解决此问题,可以在“告诉应用程序”数字”块之前向脚本中添加以下行:
这会告诉脚本打开文件以进行写访问,并且由于只需要打开文件以获得必要的权限,因此它会将其关闭。什么是AppleScript类input\u file
?该错误可能与目标路径的组成有关。@vadian我认为它只是一个字符串。它是作为带斜杠的路径字符串从命令行传入的。我想知道为什么在错误消息中没有提到目标的文件扩展名。无论如何,请尝试将输出文件设置为POSIX文件输出文件为文本
open for access file output_file
close access file output_file