Leighton Posted September 3, 2019 Posted September 3, 2019 Excuse my newbie frustration here. I though it would be the most simple workflow but I cannot figure this out. I have a specific document which I need a hard copy of once or twice a month to print out to my default printer. I would love to have a hotkey to just do this. Why is it so hard? It is a pages doc and I figured out how to open the file in pages, but it would appear that printing requires scripting knowledge beyond my expertise. It seems like such a basic need I don't understand why this is so difficult. Thanks for any help.
deanishe Posted September 3, 2019 Posted September 3, 2019 34 minutes ago, Leighton said: It seems like such a basic need I don't understand why this is so difficult. TBH, this question has little to do with Alfred. You’re asking about Pages automation, which is a Pages question. There is no universal “print document” command. You need to figure out, or—ideally—find, an AppleScript to tell Pages to open and print your document. Once you’ve got that, then you can easily configure Alfred to run it for you.
Leighton Posted September 3, 2019 Author Posted September 3, 2019 Thanks. I was unaware that there is no universal print document command. From a non-coder perspective is seems so simple.
deanishe Posted September 4, 2019 Posted September 4, 2019 The problem is that there are thousands and thousands of different types of documents. In order to print one, you need an application that can read your document to convert it into something a printer (driver) can understand.
Andrew Posted September 4, 2019 Posted September 4, 2019 @Leighton As @deanishe says, this is actually a pretty complex issue. One option is to simplify the problem by making the document more generic. If you export it as a PDF, then there are more options available for printing (even if they aren't perfect). Once you have a pdf, you could use the lpr command with a HotKey object connected to a Run Script object in an Alfred workflow. For example, if the document was called test.pdf on your desktop, the command would be lpr ~/Desktop/test.pdf Rather than giving more examples, here is a forum thread I found which discusses the issue (and highlights that it's not as simple as one may think): https://macscripter.net/viewtopic.php?id=39359 Cheers, Andrew
Leighton Posted September 4, 2019 Author Posted September 4, 2019 I actually had some luck with a very simple apple script. As I mentioned above I had figured out how to use Alfred commands to have a hot key open the document in the application Pages. I thought - If I print this manually all I'm doing is typing command-p and then when the print dialog box pops up typing enter, so what if a simple keystroke script would work - and it did! I Found this script online: tell application "Pages" activate delay 0.2 tell application "System Events" to keystroke "p" using {command down} tell application "System Events" to key code 36 end tell Now I just need a command to quit the application. and I'm golden. Thanks
deanishe Posted September 4, 2019 Posted September 4, 2019 AppleScript: tell application “Pages” to quit Leighton 1
dfay Posted September 4, 2019 Posted September 4, 2019 (edited) 8 hours ago, deanishe said: The problem is that there are thousands and thousands of different types of documents. In order to print one, you need an application that can read your document to convert it into something a printer (driver) can understand. Just use a one line AppleScript tell application "Finder" to print selection this will print using whatever the system default app for the file type is. Works fine for Pages for me. Or in an Alfred file action where Language is AppleScript and input is {query}: tell application "Finder" to print POSIX file "{query}" Edited September 4, 2019 by dfay deanishe 1
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now