Is there any "print" or "printto" equivalent command under macos ? Simply i wanna send a file to printer but its own content have to be interpreted by default program. So "lpr" or "lp" doesn't help because it's directly sending a file itself to printer. Assume that i have a office document or keynote file that i wanna print it. If i print that file in office or keynote there is no problem but if i use "lpr" or "lp" document's binary content will be written that i don't want.
PS! Sorry for my English...
you should search for "print apple event" when looking up the internet about your problem.
As far as I understand you have to open the document in default application and send this application this event. This can be done with apple script or osascript in bash.
regards,
Robert
Related
As of macOS Monterey it is possible to select text in images in Preview.
Is this OCR functionality available from AppleScript and/or JXA (JavaScript for Automation)?
In Script Editor.app File > Open dictionary... I selected the Preview.app and looked at the API for Standard Suite and Text Suite but there doesn't seem to be anything related to OCR. (The Text Suite apparently has to do with drawing text on picture and not text extraction.)
I have also searched for text recognition actions in Automator.app but didn't see anything suitable.
There isn’t (yet?) a way to directly access OCR from AppleScript, but the workaround that I’m using is to use OwlOCR. This is an app that can capture text from the screen and output it to PDF, or plant text to the clipboard. Crucially for our purposes, it can also be controlled from the command line, and you can wrap those shell commands in an AppleScript “do shell script” command.
I have a simple AppleScript which tells me url of active window in specific browser
tell application "Opera"
get URL of active tab of window 1
end tell
However I would like to see Apple Events needed to run that script, probable some of these: https://developer.apple.com/documentation/coreservices/apple_events?language=objc
My final goal is to code same script but using Apple Core Services.
I have checked Script Editor but I do not see any tab or menu where that information is displayed. Is there any way to translate that script?
Thanks in advance and regards
Yes, there are several such ways. My favorite is to use Script Debugger, which just translates the AppleScript into raw Apple events for you. Alternatively, you can run your AppleScript in an environment where export AEDebugSends=1; export AEDebugReceives=1 has been turned on.
I am building a Delphi application which opens an image and its metadata and prints it. For the Windows version I build a form to generate the PrintPreview, but in Mac I can use the Print Dialog's 'Open PDF in Preview' instead. When I click on it, a PDF file is generated and I can see it, its OK. The problem is I want to access this option directly from a button, so when the button is clicked, the PDF in Preview is opened and the user does not have to open the Print Dialog, then click the 'PDF' and then select 'Open PDF in Preview'. How can I do this?
I read about using Automator, apple scripts etc, but I still can't find it.
Is there any path this generated PDF Preview is stored, so maybe I can open it from there?...
TIA
Possible duplicate of Using Automator or Applescript or both to recursively print documents to PDF but I'll answer anyways.
To answer your question directly see the question I linked to. Basically you need to use System Events from applescript to accomplish that exactly
However, there's a quicker solution using /usr/sbin/cupsfilter. Check the man page for more.
You can call cupsfilter <an-image-file> and you'll get a PDF on stdout, courtesy of OSX's printing daemon. It looks quite configurable but I just learned about it a while ago.
If you want this to open for the user you can save it in a nice place or you can do it the one-shot way and do cupsfilter <your-image> | open -f -a "Preview" to open the PDF right up.
We have a script to send email using Microsoft outlook or Apple mail application. It will dynamically load the default email from system preference (maybe user input also), and using it to decide which mail client to use.
So the code is as following:
if (mailClientStr contains "outlook")
tell application id "com.microsoft.outlook"
-- <<< there will be error if there is no outlook installed
-- <<< even else branch will be run.
...
end tell
else
tell application id "com.apple.mail"
...
end tell
end if
On an machine which doesn't have outlook installed, and the mailClientStr will be "com.apple.mail", but this script cannot be run by osascript
It complains Can’t get application id "com.microsoft.outlook" even the first branch will not be executed. My understanding is osascript will need to access Outlook apple script interface when load and compile this script (before run it).
I can separate the outlook related code into a separate script, but because there is a lot of data to passing, it will be complex, so I don't want this workaround.
So does there any solution from the apple script language side?
From the AppleScript Language Guide:
Entering Script Information in Raw Format
You can enter double angle brackets, or chevrons («»), directly into a script by typing Option-Backslash and Shift-Option-Backslash. You might want to do this if you’re working on a script that needs to use terminology that isn’t available on your current machine—for example, if you’re working at home and don’t have the latest dictionary for a scriptable application you are developing, but you know the codes for a supported term.
You can also use AppleScript to display the underlying codes for a script, using the following steps:
Create a script using standard terms compiled against an available application or scripting addition.
Save the script as text and quit Script Editor.
Remove the application or scripting addition from the computer.
Open the script again and compile it.
When AppleScript asks you to locate the application or scripting addition, cancel the dialog.
Script Editor can compile the script, but displays chevron format for any terms that rely on a missing dictionary
You know how you can make Quicksilver display massive large type on your screen? (By Hitting . then typing free text, select View Large Type under actions and hit Enter).
Well, does anyone know of a way to do that programmatically? Also, is quicksilver even required or is it built into OS X? I would love to be able to trigger that from bash.
You can do this with Applescript, so therefore you can so it in bash with the osascript command:
osascript -e 'tell application "Quicksilver" to show large type "Hello, world."'
I think that "Large Type" was previously available in the services menu, but I don't see it in Snow Leopard. I might be wrong about that. A similar feature is found in Address Book -- right click on a telephone number.
There's no special sauce here. It's putting up a window with the text you type displayed in a large font. Duplicating the effect in a Cocoa app is trivial.
If you like to know how they exactly implemented it, you can look at the global method QSShowLargeType in their source here:
https://github.com/quicksilver/Quicksilver/blob/master/Quicksilver/Code-QuickStepInterface/QSLargeTypeDisplay.m
You could do it inside your browser with large-type.com:
$ open http://large-type.com/#YourText
It is confirmed to be fixed in the next release (after b56a7). Better keep an eye on the download area:
http://code.google.com/p/blacktree-alchemy/downloads/list