2012-11-07 55 views
1

我決定成爲傻子,並用GMail PDF服務寫我自己的Email PDF,同時學習AppleScriptObjC。我有一切工作,除了實際上能夠從打印對話框接受文件。如何使用cocoa-applescript(AppleScriptObjc)應用程序創建PDF服務?

下面的代碼是什麼樣子至今: 腳本gmailpdfAppDelegate 屬性parent:類「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

看起來你沒有任何˚F ILE處理在你的應用程序的能力呢,所以你必須實行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_ 
相關問題