使用Applescript传递PDF的“另存为打印”对话框的路径和文件名
我有一个打开电子邮件的脚本,然后我想将其保存为PDF格式。该脚本可以工作,但我不知道如何将路径和文件夹名称传递到调用“另存为PDF”后生成的对话框。这是我目前的剧本使用Applescript传递PDF的“另存为打印”对话框的路径和文件名,pdf,applescript,Pdf,Applescript,我有一个打开电子邮件的脚本,然后我想将其保存为PDF格式。该脚本可以工作,但我不知道如何将路径和文件夹名称传递到调用“另存为PDF”后生成的对话框。这是我目前的剧本 global FlName tell application "Mail" set theMsg to selection open selection set Dialogresult to the button returned of (display dialog "Process this emai
global FlName
tell application "Mail"
set theMsg to selection
open selection
set Dialogresult to the button returned of (display dialog "Process this email and Print as PDF" buttons {"Yes", "No"} default button "Yes")
if Dialogresult is "Yes" then
repeat with selectMsg in theMsg
tell selectMsg
--set background color to red --Show message processed
set FlName to subject
set check to count every word of FlName
--display dialog check
set FlName to (my FixFileName(FlName)) --strip bad characters
end tell
end repeat
set process_name to "Mail"
activate application process_name
tell application "System Events"
tell process process_name
--display dialog "proposed File Name" & return & FlName
keystroke "p" using command down
delay 2
set PDFref to sheet 1 of window 1
click menu button "PDF" of PDFref
click menu item "Save as PDF…" of menu 1 of menu button "PDF" of PDFref
tell application "Mail"
display dialog "Proposed Name " & my FlName default answer FlName & "change in the Box if Not OK"
set FlName to text returned of result
end tell
keystroke FlName
end tell
end tell
else
set Dialogresult to the button returned of (display dialog "Close this eMail" buttons {"Yes", "no"} default button "No")
if Dialogresult is "Yes" then
close window 1
end if
end if
end tell
on FixFileName(str) --Deletes characters that cannot be used in file names
set fixed_string to {}
set bad_char to {":", "/"}
repeat with c from 1 to (count every character in str)
if bad_char contains (character c of str) then
set end of fixed_string to "-"
else
set end of fixed_string to (character c of str)
end if
end repeat
fixed_string as string
end FixFileName
Peter如果生成PDF时无法设置其名称,但知道其保存位置和保存方式,请使用AppleScript重命名该文件并将其移动到所需位置。选择位置和名称可能有点笨拙,使用显示对话框让用户选择名称,使用选择文件夹让用户选择位置。在@Chuck的回答之后,是的,这有点笨拙,但是有选择文件名命令,它让用户选择名称和位置
set the FlName to (choose file name with prompt "Choose a name and location for the new PDF document:" default name "untitled.pdf")
但是,这实际上并不创建文件。下面的命令可以执行
open for access FlName
close access FlName
另一个可能的考虑是编写一个单独的PDF应用程序脚本,并通过编辑菜单将其添加到PDF下拉菜单中。不确定您必须告诉什么应用程序。。。查看此链接以获取线索:以下是Mac帮助的摘录: 您可以添加自己的项目,例如应用程序和AppleScript 脚本,然后转到PDF弹出菜单。例如,您可以添加 将石英过滤器应用于PDF文件的AppleScript脚本,或者 可以添加一个应用程序,该应用程序在PDF文件创建后立即打开该文件 创造 如果在Automator中创建打印工作流插件,则该插件是 自动添加。有关详细信息,请打开Automator,选择“帮助” Automator帮助,并搜索“打印工作流插件” 要将项目添加到PDF弹出菜单,请执行以下操作: 选择文件>打印 从PDF弹出菜单中选择编辑菜单 单击Add+按钮并选择要添加的项目 例如,如果要在Adobe中打开新创建的PDF文件 Acrobat,选择Adobe Acrobat。如果您已经创建了AppleScript脚本 如果将石英过滤器应用于文档,请选择该脚本 项目的别名保存在您的文件夹中的PDF Services文件夹中 图书馆文件夹