1

我决定鲁莽,用GMail PDF服务编写自己的Email PDF,同时学习AppleScriptObjC。我一切正常,除了实际上能够从打印对话框接受文件。

到目前为止,代码如下所示: script 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 应用程序接受该文件?

4

2 回答 2

0

看起来您的应用程序中还没有任何文件处理功能,因此您必须实现application:openFile:from NSApplicationDelegate

NSApplicationDelegate 文档

- (BOOL)application:(NSApplication *)theApplication openFile:(NSString *)filename

在 AppleScriptObjC 中,这将是:

on application_openFile_(theApplication, filename)
    -- your PDF handling code goes here
end application_openFile_
于 2013-08-06T19:54:26.880 回答
0

PDF Services 文件夹中应用程序的简单别名应该足以将 PDF 传递给应用程序。

作为 PDF 服务的任何脚本都将发送 3 个参数:文件标题、作业选项和 PDF 路径。

于 2018-03-27T15:14:01.477 回答