How to let osascript not build applescript code which will not hit at runtime?

ZijingWu

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?

adayzdone

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

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

How to display modal window using osascript or AppleScript in OS X

How do I use or force unity editor code in the runtime/build?

Run osascript (AppleScript) from launchd / launctl

Osascript/Applescript: Uncheck "Displays have separate Spaces"

Multiple Applescript lines from terminal osascript call

How to create dynamic VBA for Access code which will build

How to find at runtime with well known properties which build of MSBuild is running - .NET Core or .NET Framework

How to access UI which applescript can not access?

How to use AppleScript to let Arcobat automatically convert PDF to image(JPEG)

Code Comparison - Which is better in terms of runtime?

How to add code in runtime

how to make scanner with delimeter switch at an if depending on which delimeter was hit

How to hit a API which is PingIdentity authenticated; via python?

How to let which() throw unordered values?

Bash osascript(AppleScript) in mac terminal, run multiple commands sequentially

Getting osascript applescript to untick checkbox finder extensions in system preferences

Webpack import module at runtime without knowing which during build

How to pass multiple arguments to osascript?

AppleScript: How to get URL of Safari tab which failed to load?

AppleScript: how do I check which apps are playing audio?

How to work with WebElement which change in runtime?

How do I build a mixed java/scala project which uses java annotation code generation?

How to reuse code block which describe similiar ant build logic in groovy?

How can I have a code executed every time index is hit?

How can I hit a Foundry API from Code Repositories?

How to Abstract SIMD code to handle different datatypes without a performance hit

Rust: how to build a hashmap of functions and mutate it at runtime

How to get rootfs build timestamp at runtime?

How to get the build variant at runtime in Android Studio?