我正试图为Apple Script Sketch.app (com.bohemiancoding.sketch3)编写一篇文章。我想要做的是,创建一些图像文件,可以在浏览器中呈现素描文档。
当我在Sketch.app字典中打开Script Editior时,我看到
saveable file format enum
Sketch : The native Sketch 2 file format
PDF : Portable Document Format
TIFF : Tagged Image File Format因此,我考虑使用下面的脚本生成TIFF,但它没有工作
tell application "Sketch"
set curdoc to document 0
save curdoc in "/Users/mirza/Downloads/mew2" as TIFF
end tell我可以用保存命令创建.sketch格式的草图副本,而不是PDF或TIFF。草图是否支持PDF和TIFF使用苹果脚本?
或者还有什么别的办法。
更新
我将路径更改为apple script格式,并将文档索引设置为1。
set thisFilePath to (POSIX file "/Users/mirza/Downloads/mew2")
log thisFilePath
tell application "Sketch"
curdoc to document 1
save curdoc in thisFilePath as TIFF -- Tried with quotes as well, gives same error
end tell但是,当我运行脚本时,我得到了以下错误
Result:
error "Sketch got an error: Can’t continue curdoc." number -1708更新2
固定错误
set thisFilePath to (POSIX file "/Users/mirza/Downloads/mew2")
log thisFilePath
tell application "Sketch"
set curdoc to document 1
log (path of curdoc)
save curdoc in thisFilePath as "TIFF"
end tell但是,当我运行脚本时,我得到了以下错误
Result:
error "Sketch got an error: The document cannot be exported to the \"TIFF\" format." number -50发布于 2015-09-16 08:54:07
您的代码有很多错误,但是首先,您将发现很难使用不再可用的软件获得明确的答案。草图已经出现在版本3上一段时间了,AppleScript字典可能已经改变了。话虽如此,以下是关于您的代码的一些想法:
如果这就是字典所读取的Sketch 2所显示的内容,那么v3中的AS功能已经发生了变化。我很想帮忙,但我在任何地方都找不到v2,所以我只能在黑暗中做这件事。
set thisFilePath to choose file name--use this to select a new file;
------- a Mac AppleScript path is returned (a file specification,
------- actually, which is different from a string or alias
------- (but an alias is kind of like a file spec)
tell application "Sketch"
set curdoc to document 1--not zero-based; 1 is frontmost doc
save curdoc in thisFilePath as "TIFF"--*this is a guess
end tell所以,我不知道最后的save行会做什么,但它可能会起作用。在Sketch 3中的格式"TIFF“格式在保存时是不允许的,但是它有一个as参数作为保存的一部分,它应该与表示格式的文本字符串(如上面的"TIFF”)配对。草图2似乎有不同的方案(带有as的参数不是字符串)。如果我在Sketch 3中不使用as参数进行保存,它将保存为Sketch的本机格式。因此,您可以尝试这个没有引号(就像您有)。我只是在做v3字典告诉我做的事。以下是几个解决方案和建议:
document 1应努力引用最前端的文档;若要返回AppleScript的Mac样式路径,其形式如下:
"yourHardDriveName:Users:mirza:Downloads:new2"您还可以通过以下操作获得我这里的"yourHardDriveHame:“
tell application "Finder" to set sDr to startup disk as string然后通过做
sDr & "Users:mirza:Downloads:new2"你也可以
tell application "Finder" to set myHome to home as string它应该将Mac样式的路径返回到主文件夹。(是的,还有其他的路径,Finder也允许您获得)。
有一些东西可以玩。
https://stackoverflow.com/questions/32601184
复制相似问题