Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open safari or default browser after printing #14

Closed
hasgar-aot opened this issue Jun 25, 2021 · 11 comments
Closed

Open safari or default browser after printing #14

hasgar-aot opened this issue Jun 25, 2021 · 11 comments

Comments

@hasgar-aot
Copy link

hasgar-aot commented Jun 25, 2021

@rodyager @n1313 @mckenfra
I know this is not within the scope of this project. Do you know any way to open browser to a specific link after printing done. i tried system("open url), exec and all. no luck.
thank you

@mckenfra
Copy link
Contributor

The open command can open a URL, but it needs to have a fully-formed URL.

So this works:

open https://www.google.com

But this does not work:

open www.google.com

@hasgar-aot
Copy link
Author

@mckenfra i tried with https:// only. system() not throwing any error and give result 1(success). But it doesn’t open browser.. I don’t know is it because any permission limitation of printer module or not. i tried exec functions also to run shell script. Same result. Any thoughts?

@rodyager
Copy link
Owner

rodyager commented Jun 26, 2021 via email

@mckenfra
Copy link
Contributor

@rodyager Yes I wanted the PDFs to appear in ~/Downloads rather than /var/spool/pdfwriter/.

I got it working using Folder Actions. I modified RWTS-PDFwriter so that it automatically adds a Folder Action to /var/spool/pdfwriter as part of the installation process of the driver.

Then, whenever a user subfolder is created under /var/spool/pdfwriter, my Folder Action automatically creates another Folder Action on that user subfolder such that anything that appears in the user subfolder (i.e. any PDF printed using RWTS-PDFwriter) is automatically moved to the user's Downloads directory.

It works pretty well!

If you like I could create a pull request to merge it into your project, but it does add more complexity, so I understand if you'd prefer to keep your driver simple 👍

@rodyager
Copy link
Owner

rodyager commented Jun 26, 2021 via email

@mckenfra
Copy link
Contributor

Ok I'll create a pull request.

Only problem is that the "Folder Actions" functionality is implemented using AppleScript, and I've checked these scripts into my branch as .scpt files. But git treats .scpt files as opaque binary files, which prevents you from viewing the underlying source code on Github. To see the Applescript source code, you have to clone the project to your Mac computer and open the .scpt files using macOS Applescript Editor.

Ideally the plain-text applescript source would be checked-in to git, and then this would be compiled to .scpt files during the build process. So I'll need to get this extra build step working before doing the pull request.

@hasgar-aot
Copy link
Author

hasgar-aot commented Jun 26, 2021

@mckenfra how did you triggered folder actions from pdfwriter? May be using apple script i can open browser too. Could you please share that code snippet(apple script trigger) here? Or pull request will also work :)

@mckenfra
Copy link
Contributor

@hasgar-aot Yes you can look at the code once I've done the pull request. The tricky part is making it work automatically for any user - you need a Folder Action on the parent /var/spool/pdfwriter folder that automatically detects when a user subfolder is created. This parent Folder Action then needs to add another Folder Action to the new user subfolder to do the actual automatic moving of the printed PDFs to that user's ~/Downloads folder.

But in your case, all you would need to do is create your own Folder Action on your ~/Downloads folder. Your Folder Action would detect whenever a file named job_* appears and then would call open https://my-url.

@hasgar-aot
Copy link
Author

@mckenfra How will that Apple script be created in the /Downloads folder with limited permissions? I need this to be done by the printer module itself without any manual effort. Will we write that in a post-installation script?

@mckenfra
Copy link
Contributor

mckenfra commented Jun 27, 2021

@hasgar-aot Your Folder Action would be created on the user's ~/Downloads folder, which the user has permissions to access, so there would be no problem with permissions. In fact, I'm thinking we should allow the user to change the destination folder as part of the installation process.

Also unfortunately I think Folder Actions are installed for the current-user-only, not system-wide. So after one user installs the RWTS-PDFwriter driver on a Mac computer, any other users who then log-in will need to run the Change PDFwriter Output Dir script, to configure where they want their PDFs to end up (otherwise they'll stay in their original location of /var/spool/pdfwriter/<user>). I don't think (sadly) a Folder Action can be enabled by default system-wide for all users, i.e. to always move printouts to the current user's ~/Downloads folder by default.

So for your situation, maybe you could create another script that the user needs to run after the RWTS-PDFwriter driver is installed, to setup your open-url Folder Action? You could also do a custom build of RWTS-PDFwriter to add you custom setup script to /Library/Printers/RWTS/PDFwriter/Folder Actions/, which is where my scripts are going, and then have the post-installation run your custom script as part of installation. But again, each new user who logs-in to the same Mac computer will need to run your script again (once) to install your Folder Action in their login environment.

@hasgar-aot
Copy link
Author

@mckenfra thank you very much. i'll try. it would be nice if you can do a pull request :)

@rodyager rodyager closed this as not planned Won't fix, can't repro, duplicate, stale Jun 19, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants