Skip to main content
Whatevermajorloser
Inspiring
November 23, 2015
解決済み

Open URL in browser via Photoshop

  • November 23, 2015
  • 返信数 1.
  • 9766 ビュー

Is this possible? I don't need a clickable link for the user or anything, I just need the script to open a URL in the users default browser. How would I go about doing this?

このトピックへの返信は締め切られました。
解決に役立った回答 xbytor2

function openURL(url) {

  var fname = "shortcut.url";

  var shortcut = new File(Folder.temp + '/' + fname);

  shortcut.open('w');

  shortcut.writeln('[InternetShortcut]');

  shortcut.writeln('URL=' + url);

  shortcut.writeln();

  shortcut.close();

  shortcut.execute();

  shortcut.remove();

};

返信数 1

xbytor2解決!
Inspiring
November 23, 2015

function openURL(url) {

  var fname = "shortcut.url";

  var shortcut = new File(Folder.temp + '/' + fname);

  shortcut.open('w');

  shortcut.writeln('[InternetShortcut]');

  shortcut.writeln('URL=' + url);

  shortcut.writeln();

  shortcut.close();

  shortcut.execute();

  shortcut.remove();

};

Whatevermajorloser
Inspiring
November 23, 2015

Thanks xbytor2, this works great! I don't quite understand how exactly it works though. When I first ran it, it just opened Safari (which isn't my default browser) but didn't load the page. It was only when removed shortcut.remove() did it actually open the URL.

If you don't mind explaining, I'd love to know what each line of this function does it order for it to work?

Inspiring
November 23, 2015

They way I figure this out was to drop a link from a browser on to my Desktop. I did this with, IE and Firefox on Win7 and Safari and Firefox in OS X.

It turns out the simplest format is

[ImageShortcut]

URL=https://forums.adobe.com/

Put that in to a file with a .url  extension and you're good to go. The only weird thing is that Windows requires a blank line at the end of the file while OS X doesn't care.

I probably should remove the remove()  call.

All of the stuff in the code is just simple File I/O code. Nothing magic.