• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
0

Is it possible to launch an AppleScript from an InDesign extend script?

Engaged ,
Jan 23, 2019 Jan 23, 2019

Copy link to clipboard

Copied

I have an AppleScript on my mac desktop that builds an email and I would like to launch it from within a InDesign extend script. Is this possible and if so can you give an example?

Thanks for any help.

TOPICS
Scripting

Views

1.1K

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

Engaged , Jan 23, 2019 Jan 23, 2019

David: I have a VB script that handles the emailing. To run it from ExtendScript, it's simply:

File("path//to/your/script/file/here").execute();

Before that happens, the ExtendScript sets environment variables to carry the data for the email:

$.setenv("msg_to","some.body@wherever.com");

$.setenv("msg_subject","whatever");

$.setenv("msg_text","yadda, yadda, yadda:);

The VB script reads the same system variables to construct the email.

There may be better ways of doing this (I'm posting this in the hope

...

Votes

Translate

Translate
Engaged ,
Jan 23, 2019 Jan 23, 2019

Copy link to clipboard

Copied

David: I have a VB script that handles the emailing. To run it from ExtendScript, it's simply:

File("path//to/your/script/file/here").execute();

Before that happens, the ExtendScript sets environment variables to carry the data for the email:

$.setenv("msg_to","some.body@wherever.com");

$.setenv("msg_subject","whatever");

$.setenv("msg_text","yadda, yadda, yadda:);

The VB script reads the same system variables to construct the email.

There may be better ways of doing this (I'm posting this in the hope that the experts who hang out here will tell us what those are), but this works. I would guess that your AppleScript would need to be saved in the form of an applet. It might also work for the ExtendScript piece to use doScript() instead of File.execute().

Hope this helps

Bob

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Engaged ,
Jan 23, 2019 Jan 23, 2019

Copy link to clipboard

Copied

This works thank you.

Do you know or have you tried to pass a variable to the script?

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Engaged ,
Jan 23, 2019 Jan 23, 2019

Copy link to clipboard

Copied

I was trying to explain: Use $.setenv in ExtendScript to establish a name and a value for the variable. Then your AppleScript uses the same variable name to get the value. We use three environment variables, for the address(es), the subject and the message. This is in Windows.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guru ,
Jan 24, 2019 Jan 24, 2019

Copy link to clipboard

Copied

Here's a function from a script I wrote back in 2010 (so things may have changes since then).

function SendEmail(myFile, mySubject, myMessage) {

    if (File.fs == "Macintosh") {

        var myPath = myFile.fsName;

        var myFolderPath = myFile.parent.fsName;

        if (myPath.match("/Volumes/") != null) {

            var myMacPath = myPath;

            var myAppleScript = 'tell application "Mail"\r';

            myAppleScript += 'set theSignature to signature "' + mySignature + '"\r';

            myAppleScript += 'set newMessage to make new outgoing message\r';

            myAppleScript += 'tell newMessage\r';

            myAppleScript += 'set visible to true\r';

            myAppleScript += 'set subject to "' + mySubject + '"\r';

            myAppleScript += 'set content to "' + myMessage + '"\r';

            myAppleScript += 'set message signature to theSignature\r';

            myAppleScript += 'make new attachment with properties {file name:"' + myMacPath + '"} at after the last paragraph\r';

            myAppleScript += 'end tell\r';

            myAppleScript += 'end tell\r';

        }

        else {

            var myMacPath = myPath.replace(/\//g, ":");

            var myAppleScript = 'tell application "Mail"\r';

            myAppleScript += 'set theSignature to signature "' + mySignature + '"\r';

            myAppleScript += 'set newMessage to make new outgoing message\r';

            myAppleScript += 'tell newMessage\r';

            myAppleScript += 'set visible to true\r';

            myAppleScript += 'set subject to "' + mySubject + '"\r';

            myAppleScript += 'set content to "' + myMessage + '"\r';

            myAppleScript += 'set message signature to theSignature\r';

            myAppleScript += 'tell application "Finder"\r';

            myAppleScript += 'set MyDiskName to name of startup disk\r';

            myAppleScript += 'end tell\r';

            myAppleScript += 'make new attachment with properties {file name:(MyDiskName &"' + myMacPath + '") as alias} at after the last paragraph\r';

            myAppleScript += 'end tell\r';

            myAppleScript += 'end tell\r';

        }

   

    var myScriptDataFolder = new Folder(Folder.userData.absoluteURI + "/ScriptsData");

    if (!myScriptDataFolder.exists) myScriptDataFolder.create();

        var myAsFile = new File( myScriptDataFolder.absoluteURI + "/Temp.scpt");

        myAsFile.encoding = "UTF-8";

        myAsFile.open("w");

        myAsFile.write("\uFEFF" + myAppleScript);

        myAsFile.close();

        app.doScript(myAsFile, ScriptLanguage.applescriptLanguage);

    }

}

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Sep 06, 2021 Sep 06, 2021

Copy link to clipboard

Copied

LATEST

Hello David and Robert,
In case anyone end up here, I use a json file to pass data from a script to another. It works well and it might be more convenient that $.setenv variables in some cases. 
For instance, here is my workflow : I export lot of designs with an ai script, then store their id and other infos in a json file. After that, a psd script get the list and c
reate mockups from it. When it's done, my json file get updated and voilà. 

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines