• 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 an AI Javascript? Part II

Engaged ,
Jan 31, 2022 Jan 31, 2022

Copy link to clipboard

Copied

Good Morning,

 

Jumping off from this post back in 2012
https://community.adobe.com/t5/illustrator-discussions/link-to-a-web-page-from-ai-javascript/td-p/45...

from  Muppet_Mark-phjQ9l   Guru , Dec 06, 2012

 

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

f.open( 'w' );

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

f.close();

f.execute();

When the script creates the URL Shortcut on my desktop is there a way to have it update the URL everytime I run the script to pull up the Order Number?

var strEnter = prompt("Please Enter the New Order # (a 7-digit number)", "");

var f = File( Folder.desktop + '/TestURL.url' );
f.open( 'w' );
f.write( '[InternetShortcut]' + '\r' + 'URL=http://MyWebSite&orderNumber=' + strEnter + '\r' );
f.close();
f.execute();

Thank you!

TOPICS
Scripting

Views

311

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

Community Expert , Jan 31, 2022 Jan 31, 2022

@BryanPagenkopf 

If I understand you correctly - does this work for you?

//for example
//https://community.adobe.com/html/assets/banner2.png
var Filename_or_Number_does_not_matter = prompt("Please Enter the New Order # (a 7-digit number)", "banner2.png");

var f = File( Folder.desktop + '/TestURL.url' );
f.open( 'w' );
f.write( '[InternetShortcut]' + '\r' + 'URL=https://community.adobe.com/html/assets/' + Filename_or_Number_does_not_matter + '\r' );
f.close();
f.execute();

 

Votes

Translate

Translate
Adobe
Valorous Hero ,
Jan 31, 2022 Jan 31, 2022

Copy link to clipboard

Copied

You can have a CEP extension if you want to pull up the order right there inside of Illustrator, but otherwise a good way is to do the following:
1) Create an HTML page somewhere on your desktop, you can use regular VSCode without any ESTK for this.
2) Put a script into the HTML page which has a function that tries to load a JS script from the same folder and is named a certain name that doesn't change. Make this function repeat in an interval every second or less, its purpose is to find and load a JS file which has some data inside it.
3) With your JSX extendscript use a method to write the JS file to that location in step 2. Make this JS file have contents such as var data = { "url" : "my-url.com"}; When the HTML page's javascript finds and loads this file, make it change the window.location object to the url inside the data that was just found. Now the page will redirect to the url and that's that.
4) Clean up the written JS file using JSX by waiting a good second (longer than HTML page's javascript interval)  with $.sleep(1000) and then removing the file. This way when you press the back button or go to the page by double clicking the HTML file from the filesystem, it will run the time interval function but not find any JS file with data and therefore will not redirect anywhere.This way you can be more sure that only script-activated actions are responsible for the website someone's about to see.

I have a complex example in github, you can observe this part of the example to see such an HTML page and JS file at work. The HTML page looks huge, the time-interval script does a lot. You can strip all of that content out and just narrow down on the structure of the time-interval method itself.

 

To recap:

  • You can use javascript to navigate to a web page.
  • You can create an HTML file with a javascript that navigates to a web page.
  • The javascript that navigates to a web page can be triggered by a time-interval method also in the HTML file.
  • The time-interval method needs to be searching for a file that is written by JSX.
  • When the time-interval method loads the file written by JSX, it uses the info inside to trigger the HTML file script method that navigates to a the web page as specified by the info inside.

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 ,
Jan 31, 2022 Jan 31, 2022

Copy link to clipboard

Copied

@BryanPagenkopf 

If I understand you correctly - does this work for you?

//for example
//https://community.adobe.com/html/assets/banner2.png
var Filename_or_Number_does_not_matter = prompt("Please Enter the New Order # (a 7-digit number)", "banner2.png");

var f = File( Folder.desktop + '/TestURL.url' );
f.open( 'w' );
f.write( '[InternetShortcut]' + '\r' + 'URL=https://community.adobe.com/html/assets/' + Filename_or_Number_does_not_matter + '\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
Engaged ,
Feb 01, 2022 Feb 01, 2022

Copy link to clipboard

Copied

@pixxxelschubser   That worked the first time I used the script on order 5994589, but when I ran it again for order 5994699 it just reopened the webpage for the first order  number 5994589.

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 ,
Feb 01, 2022 Feb 01, 2022

Copy link to clipboard

Copied

@pixxxelschubser I just restarted my computer and now it is working 🙂

 

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
Engaged ,
Feb 04, 2022 Feb 04, 2022

Copy link to clipboard

Copied

@pixxxelschubser so it worked great for a few days and then this morning when I was demonstrating it; it would only pull up a Previous Order# site, not the one associated with the Order# I was currently working on.   

Is there an extra step that could be included in the script to ensure it cannot pull up the site from a previous use?

 

Thanks appreciate the assist!

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 ,
Feb 04, 2022 Feb 04, 2022

Copy link to clipboard

Copied

  1. Are you able to create a sample page with sample folders (without confidential data) for testing?
  2. Are you running the script from Illustrator?
  3. Are there any other changes in the script (other than the specific web address)? If so, what are they?
  4. Can you show the code for a (working) sample page (without confidential data)?

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 ,
Feb 04, 2022 Feb 04, 2022

Copy link to clipboard

Copied

1. I can have a generic Google Search Page if that helps.
2. I am running the Script from Inside Illustrator

3. No Changes in the Script that I am aware of

4. Here is the Script with the Generic Google Search for the website

 

var strEnter = prompt("Please Enter the New Order #", "");

if (strEnter != null) {
  var doc = app.activeDocument;
  var PTS_IN = 72;
  var width = 90 * PTS_IN;
  var height = 90* PTS_IN;
  var presets = app.startupPresetsList;
  var preset = presets[3];
  var docPreset = new DocumentPreset();

  docPreset.title = strEnter;
  docPreset.units = RulerUnits.Inches;
  docPreset.width = width;
  docPreset.height = height;
  var doc = app.documents.addDocument(preset, docPreset, false);


  } else { alert ("Please Try Again Invalid Order # :" + strEnter);
};

// Open Order Preview Screen for the Order # Entered.  Added on 2/1/22
var f = File( Folder.desktop + '/Search.url' );
f.open( 'w' );
f.write( '[InternetShortcut]' + '\r' + 'URL=https://www.google.com/search?q=' + strEnter + '\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
Community Expert ,
Feb 04, 2022 Feb 04, 2022

Copy link to clipboard

Copied

LATEST

Works for me on Window with Firefox as expected. The web page with the number is opened and a new document is created with the number as name.
The script is started again:
Internet page with the new number is opened and a new document with the new number as name is created.

 

Please check the hierarchy of your website.

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