我决定蛮干,用GMail PDF服务编写自己的电子邮件PDF,同时学习AppleScriptObjC。我已经完成了所有工作,除了实际上能够接受打印对话框中的文件。
以下是目前代码的样子: 脚本gmailpdfAppDelegate property parent:class“NSObject”
property recipientField : missing value
property subjectField : missing value
property fromField : missing value
property passwordField : missing value
property messageField : missing value
property pdfFile : missing value
on ButtonHandlerCancel_(sender)
quit
end ButtonHandlerCancel_
on ButtonHandlerSend_(sender)
set recipient to recipientField's stringValue()
set subject to subjectField's stringValue()
set fromUser to fromField's stringValue()
set pw to passwordField's stringValue()
set message to messageField's stringValue()
set sendEmailScript to (current application's NSBundle's mainBundle()'s pathForResource_ofType_("sendEmail", "")) as string
set emailserverInfo to " -s smtp.gmail.com:587 -xu '" & fromUser & "' -xp '" & pw & "' -m '" & message & "' "
do shell script quoted form of sendEmailScript & " -t " & recipient & " -u " & subject & " -f '" & fromUser & "' " & emailserverInfo
quit
end ButtonHandlerSend_
on applicationWillFinishLaunching_(aNotification)
-- Insert code here to initialize your application before any files are opened
set fromField's stringValue to do shell script "defaults read org.ryancollins.GMail-PDF 'fromDefault'"
set passwordField's stringValue to do shell script "security 2>&1 >/dev/null find-generic-password -ga gmailpdf |ruby -e 'print $1 if STDIN.gets =~ /^password: \"(.*)\"$/'"
end applicationWillFinishLaunching_
on applicationShouldTerminate_(sender)
-- Insert code here to do any housekeeping before your application quits
set fromDefault to fromField's stringValue()
do shell script "defaults write org.ryancollins.GMail-PDF 'fromDefault' '" & fromDefault & "'"
set passwordDefault to passwordField's stringValue()
do shell script "security add-generic-password -a gmailpdf -s email -p '" & passwordDefault & "' -U"
return current application's NSTerminateNow
end applicationShouldTerminate_
end script
编译并添加到PDF Services文件夹时,我收到此错误(该应用程序名为GMail PDF:
The document “Google News.pdf” could not be opened. GMail PDF cannot open files in the “Portable Document Format (PDF)” format.
如何让AppleScriptObjC应用程序接受该文件?
答案 0 :(得分:0)
您的应用中似乎还没有任何文件处理功能,因此您必须从application:openFile:
实施NSApplicationDelegate
:
来自NSApplicationDelegate documentation:
- (BOOL)application:(NSApplication *)theApplication openFile:(NSString *)filename
在AppleScriptObjC中,它将是:
on application_openFile_(theApplication, filename)
-- your PDF handling code goes here
end application_openFile_
答案 1 :(得分:0)
PDF Services文件夹中应用程序的简单别名应足以将PDF传递给应用程序。
作为PDF服务的任何脚本都将发送3个参数:文件标题,作业选项和PDF路径。