rodyager / RWTS-PDFwriter

An OSX print to pdf-file printer driver
GNU General Public License v2.0
823 stars 78 forks source link

Launch application after generate PDF #9

Closed faythe-cfortuno closed 4 years ago

faythe-cfortuno commented 4 years ago

I am trying to launch an application after the pdf file is created in /var/spool/cups/pdfwriter/{user}. I just added this code after de writepdf function is called:

NSTask *task = [[NSTask alloc] init]; task.launchPath = @"/usr/bin/open"; task.arguments = @[@"-a", @"/Applications/Gestiona envia/GestionaEnvia.app", @"--args", @"print"]; [task launch];

No exception or error is launched, but the application does not open. The path is correct. Any idea why this can be?

Thanks for your code!!

rodyager commented 4 years ago

A few things.

  1. I’d set the launchPath to be the path to your apps executable @“/Applications/Gestiona envia/GestionaEnvia.app/Contents/GestoniaEnvia” rather than getting there indirectly through open.

  2. Since launchPath is deprecated you might want to use executableURL instead, in which case you need an NSURL that points to the executable.

  3. PrintDrivers are affected by Sandbox when called from Sandboxed apps. I expect that is what is really happening here and preventing you from launching a non-related app. Not sure how to get around it. You could experiment by trying it using the Print function from an old unSandboxed app and see if that works (but its probably bad news if it does unless you can build your app’s functionality into pdfWriter.

Rod

On 23 Jul 2020, at 7:16 pm, faythe-cfortuno notifications@github.com<mailto:notifications@github.com> wrote:

I am trying to launch an application after the pdf file is created in /var/spool/cups/pdfwriter/{user}. I just added this code after de writepdf function is called:

NSTask *task = [[NSTask alloc] init]; task.launchPath = @"/usr/bin/open"; task.arguments = @[@"-a", @"/Applications/Gestiona envia/GestionaEnvia.app", @"--args", @"print"]; [task launch];

No exception or error is launched, but the application does not open. The path is correct. Any idea why this can be?

Thanks for your code!!

— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHubhttps://github.com/rodyager/RWTS-PDFwriter/issues/9, or unsubscribehttps://github.com/notifications/unsubscribe-auth/AAKSADPZOJ5T5ZVQMPSONLTR475YBANCNFSM4PFQ24VQ.

faythe-cfortuno commented 4 years ago

Thanks for your reply,

You were absolutely right. Due to security issues pdfwriter was not able to launch another app. To simulate that, I made a folder action using applescript and javascript in order to launch the app when pdfwriter creates the file in a specified folder.

Thank you again for your project, it was really helpfull to me