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

Link to a web page from AI javascript?

Explorer ,
Dec 05, 2012 Dec 05, 2012

Copy link to clipboard

Copied

I've written a script with a ScriptUI interface, which other people will be using. I'd like to include a 'help' button in the interface, which ideally would connect to a web page with more details. (The alternative is to create the 'help' window in javascript, but the web page already exists and it would be a shame not to use it.)

From what I've read, other Creative Suite programs may be able to connect to the web with javascript, but apparently not Illustrator. Can anyone please confirm this is so? Or better, point me towards a solution!

With thanks.

TOPICS
Scripting

Views

5.0K

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

Guru , Dec 08, 2012 Dec 08, 2012

As it would appear to work mac/pc then I would just wrap it to use like so… I've changed the location to the system temporary junk… Out of sight, and it should get cleaned out at system restart me thinks… I did try f.remove() but that would appear to take place faster than the file can be evoked so I removed it. I doubt very much the size of these would ever be a problem…

openURL( 'www.google.com' );

function openURL( address ) {

          var f = File( Folder.temp + '/aiOpenURL.url' );

          

 

...

Votes

Translate

Translate
Adobe
Guru ,
Dec 05, 2012 Dec 05, 2012

Copy link to clipboard

Copied

Did you already look at the socket object in the JavaScript Tools Guide…?

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
Explorer ,
Dec 05, 2012 Dec 05, 2012

Copy link to clipboard

Copied

Yes, it's useful. But sadly, only if you're running Bridge, InDesign, InCopy, After Effects or Photoshop! The object is not available to Illustrator users.

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 ,
Dec 05, 2012 Dec 05, 2012

Copy link to clipboard

Copied

Oh sorry now I see… had't noticed AI was missing from the list… How silly…

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
Community Expert ,
Dec 05, 2012 Dec 05, 2012

Copy link to clipboard

Copied

using windows, I created a link file (mac Alias?) to the web page, and called the link.

// google.url is a link file that points to https://www.google.com/

var file = new File('c:/temp/google.url');

if (file.exists)

    file.execute();

else

    alert('file does not exist');

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
Advisor ,
Dec 05, 2012 Dec 05, 2012

Copy link to clipboard

Copied

This one works on both platforms:

function GotoLink(url){

    url = url || "http://tomaxxi.com";

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

        var body = 'tell application "Finder"\ropen location "'+url+'"\rend tell';

        app.doScript(body,ScriptLanguage.APPLESCRIPT_LANGUAGE);

    } else {

        var body =  'dim objShell\rset objShell = CreateObject("Shell.Application")\rstr = "'+url+'"\robjShell.ShellExecute str, "", "", "open", 1 '

        app.doScript(body,ScriptLanguage.VISUAL_BASIC);

    }

}

Hope that helps.

--

Marijan (tomaxxi)

http://tomaxxi.com

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
Advisor ,
Dec 05, 2012 Dec 05, 2012

Copy link to clipboard

Copied

Or even better:

function GotoLink ( url ) {

    var

        body, language;

    url = url || "http://tomaxxi.com";

    if ( File.fs == "Macintosh" )

        body = 'tell application "Finder"\ropen location "' + url + '"\rend tell',

        language = ScriptLanguage.APPLESCRIPT_LANGUAGE;

    else

        body = 'dim objShell\rset objShell = CreateObject("Shell.Application")\rstr = "' + url + '"\robjShell.ShellExecute str, "", "", "open", 1 ',

        language = ScriptLanguage.VISUAL_BASIC;

    app.doScript ( body, language );

}

--

Marijan (tomaxxi)

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
Explorer ,
Dec 05, 2012 Dec 05, 2012

Copy link to clipboard

Copied

Many, many thanks to Carlos and Marijan - very grateful for your expertise. Will try things out very shortly (it's late here) and report back.

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
Contributor ,
Dec 05, 2012 Dec 05, 2012

Copy link to clipboard

Copied

hi

Those codes work for InDesign, but not for Illustrator(Ai)...

because Ai doesn't have 'doScript' method.

mg.

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
Explorer ,
Dec 06, 2012 Dec 06, 2012

Copy link to clipboard

Copied

As milligramme noted, AI does not have the 'doScript' method, so it seems that Marijan's elegant solution is not available. But I can report encouraging progress in other directions.

• Carlos' script using Windows link files also works on Mac OS/Safari.

Mac users can create a .url link file in TextWrangler or BBedit (TextEdit may not work). The format is:

[InternetShortcut]

URL=http://www.google.com

…but note that Safari needs a line feed at the end (press Return in TextWrangler or BBedit - this is where TextEdit may fall down). Use '.url' as the filetype suffix.

• Carlos' script also works on Mac OS with .webloc files.

This potentially opens up other Mac browsers than Safari, though I have not been able to confirm this. You create a .webloc file by dragging the URL from (say) Safari's address line to the desktop - be sure to re-name the file something like 'linkname.webloc' as it won't work with the auto-created filename.

So we have the potential for a cross-platform solution.

One further question, please: my script will be distributed to both PC and Mac users, and I don't want to ask them to install link files at specific locations. A relative address for the link file (i.e. in the same folder as the script) would be better, but I don't seem to be able to get relative addresses to work. Better still would be to embed the link file as a binary in the script itself. Can someone show me how to do this? (I've tried the method for embedding images as binaries given in the very worthwhile 'ScriptUI for Dummies', but it creates an empty file…).

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 ,
Dec 06, 2012 Dec 06, 2012

Copy link to clipboard

Copied

David, have script write your text files on the fly… Then execute them… You can write the required info like so… Just write to the temp folder location…

var f = File( Folder.desktop + '/TestURL.url' );

f.open( 'w' );

f.write( '[InternetShortcut]' + '\r' + 'URL=http://www.google.com' + '\r' );

f.close();

f.execute();

On the mac I think this will open in what ever is set to the default browser in launchservices…

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
Explorer ,
Dec 07, 2012 Dec 07, 2012

Copy link to clipboard

Copied

I don't think I would ever have thought of something like that. Mark, thank you.

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
Community Expert ,
Dec 07, 2012 Dec 07, 2012

Copy link to clipboard

Copied

good one Mark,

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 ,
Dec 07, 2012 Dec 07, 2012

Copy link to clipboard

Copied

To be honest it looked obvious to pretty me…? Does this work on the PC? I have not looked if different browsers require differing strings but it worked first time for me… Not surprised at the uneven playing field pointed out by David it's so offen the case… Just presumed socket was available to all apps… When you script a couple like I try to do there can be a little fuzzieness from time to time… As of CS3 the mac should be able to write and execute shell although I have not had need to this yet… Unfortunately AI appears to languish behind the rest on several fronts… but we try our best…

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
Community Expert ,
Dec 07, 2012 Dec 07, 2012

Copy link to clipboard

Copied

yeah, that was the next logical test....it does work in Windows, opened in my default browser (chrome)

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
Mentor ,
Dec 08, 2012 Dec 08, 2012

Copy link to clipboard

Copied

Very nice Muppet Mark, good thread.

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 ,
Dec 08, 2012 Dec 08, 2012

Copy link to clipboard

Copied

As it would appear to work mac/pc then I would just wrap it to use like so… I've changed the location to the system temporary junk… Out of sight, and it should get cleaned out at system restart me thinks… I did try f.remove() but that would appear to take place faster than the file can be evoked so I removed it. I doubt very much the size of these would ever be a problem…

openURL( 'www.google.com' );

function openURL( address ) {

          var f = File( Folder.temp + '/aiOpenURL.url' );

          

          f.open( 'w' );

          

          f.write( '[InternetShortcut]' + '\r' + 'URL=http://' + address + '\r' );

          

          f.close();

          

          f.execute();

 

};

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
Explorer ,
Dec 10, 2012 Dec 10, 2012

Copy link to clipboard

Copied

May I just thank all who contributed to this thread and helped answer my question, especially MuppetMark and CarlosCanto. You've created an elegant workaround to a clear deficiency in Illustrator's scripting capability, and I for one am grateful.

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 ,
Dec 10, 2012 Dec 10, 2012

Copy link to clipboard

Copied

I agree, David. They are two great and selfless guys, among the countless other contributors on this forum. I don't know where they find the time.

I, for one, will surely be buying each of them a beer at the Adobe AI Scripting Christmas Party!

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 ,
Dec 10, 2012 Dec 10, 2012

Copy link to clipboard

Copied

Hum beer we like those… derby day yesterday so I had a few… and a few more… Larry is in charge of christmas party… not had my memo yet either…? mvp gone to his head and forgot all his responsibilities… it's a much bigger venue these days a busier forum ( whole cloakroom to ourselves ).

edit…

jong catering…

carlos entertainment…

get ya skates on

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
Community Expert ,
Dec 10, 2012 Dec 10, 2012

Copy link to clipboard

Copied

what's your team? city or united?

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 ,
Dec 10, 2012 Dec 10, 2012

Copy link to clipboard

Copied

muppet mark is manc… that makes me a looser but for sunday only… that other rubbish is for the rest of the world

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
Community Expert ,
Dec 10, 2012 Dec 10, 2012

Copy link to clipboard

Copied

LATEST

Just 'cause I wasn't here to nominate someone else I get stuck with planning the party, huh? With the diversity of time zones, could be quite long. Seeing as how I'm -8 you guys are going to have to be up real late or I have to start real early.

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