Skip to main content
Inspiring
December 5, 2012
Answered

Link to a web page from AI javascript?

  • December 5, 2012
  • 1 reply
  • 6543 views

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.

This topic has been closed for replies.
Correct answer Muppet Mark

Very nice Muppet Mark, good thread.


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();

 

};

1 reply

Inspiring
December 5, 2012

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

Inspiring
December 5, 2012

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.

Inspiring
December 6, 2012

hi

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

because Ai doesn't have 'doScript' method.

mg.


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…).