Copy link to clipboard
Copied
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?
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();
};
Copy link to clipboard
Copied
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();
};
Copy link to clipboard
Copied
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?
Copy link to clipboard
Copied
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]
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.
Copy link to clipboard
Copied
Thank you! Much appreciated.
Copy link to clipboard
Copied
Sorry to ask another question, xbytor2, but do you know if it's possible to get it to open the URL in a specific browser?
Copy link to clipboard
Copied
I don't have a clue.
Copy link to clipboard
Copied
You should probably use the browser the user chose to set as their default browser application.
You can test which OS the users is running and the test if the browser you want to use is install in its normal location. If it exists you could most likely write some system command file like a DOS bat file if windows to start the browser passing it an HTML file you wrote that redirects the browser the the URL you want opened. What I did when I wanted to open my Help URL was I wrote a HTML file and through it over the wall. Let the user default file association application open the html file. I wrote the file to temp space and did not remove it.
// A Photoshop Script by JJMack's
// This script is supplied as is. It is provided as freeware.
// The author accepts no liability for any problems arising from its use.
#target photoshop
app.bringToFront();
/*
<javascriptresource>
<name>HelpPhotoCollageToolkit</name>
<about>$$$/JavaScripts/HelpPhotoCollageToolkit/About=Web Help for JJMack's Photo Collage Toolkit.^r^rCopyright 2010 Mouseprints.^r^rOpen Browser Toolkit Help Page</about>
<category>JJMack's Collage Script</category>
</javascriptresource>
*/
try{
var URL = new File(Folder.temp + "/PhotoCollageToolkit.html");
URL.open("w");
URL.writeln('<html><HEAD><meta HTTP-EQUIV="REFRESH" content="0; url=http://www.mouseprints.net/old/dpr/PhotoCollageToolkit.html"></HEAD></HTML>');
URL.close();
URL.execute(); // The temp HTML file created
}catch(e){
alert("Error, Can Not Open.");
};
Copy link to clipboard
Copied
Hi JJMack,
I guess the script xbytor2 provided should open it in their default chosen browser, but on a OSX it always opens it in Safari, regardless of which one they have set as their default.
Thank you very much for the script - I'll give this a shot and see what I can do. Otherwise, I don't think it's the end of the world if it opens in another browser
Copy link to clipboard
Copied
This is very ugly solution to my taste, but indeed it remains as the only one familiar to me to use in my script for Adobe Photoshop CC 2018. If anyone has better API call not involving the creation of local temp file, but opening system's default browser instead would be most welcome!
Anyways... Thanks JJMack​ for sharing!
Copy link to clipboard
Copied
system('"'+ File('/C/Program Files (x86)/Google/Chrome/Application/chrome.exe').fsName + '" www.adobe.com')
System is limited so if browser wasn't opened yet, then Photoshop.exe will take it as its child and will take care of as long as you won't cut umbilical cord. You have to close either command prompt or browser, both manually. Only then you can use back Photoshop / ExtendScript ToolKit. If browser was opened before you executed that system command then Photoshop just added new tab to existing one, so wouldn't be "resposible" for it's working, as it wasn't run by Photoshop.exe process. If you used bat then you can write to file multiline commands, and this way start chrome.exe process not by Ps but other spot in your system. But you don't want to create file for this task, so you're not having big choise you're stuck with side-effect
Copy link to clipboard
Copied
True indeed. Amd this absolute path to a specific browser is also not to my taste. Thank you for mentioning it though. Indeed. JavaScript might be not the best option for Adobe Photoshop. 😞
Copy link to clipboard
Copied
Here's something with .bat (what you didn't want), but only to kill the command prompt process that ran internet browser. It opens specific browser though, but if not specific one which one you'd like to be opened, that set as default? I don't know method for opening default one yet, but I know that with visual basic (.vbs) you can open command line silently. Still there is need to save file to disk to execute it.
(fle = new File(Folder.temp.absoluteURI + '/' + 'taskkill.bat')).open('w')
fle.write('ping 127.0.0.1 -n .1 > nul\rtaskkill /im cmd.exe'), fle.close(), fle.execute()
system('"' + File('/C/Program Files (x86)/Google/Chrome/Application/chrome.exe')
.fsName + '" www.adobe.com'), fle.remove()
EDIT: I found it - that was easier than making whole above code. You open default browser without killing cmd process
system('start http://adobe.com')
Copy link to clipboard
Copied
FYI, the fle.execute() call will not work on OSX. The file's execute bit is not set by default. I don't know if I ever came up with a solution that works for both OSs.
Copy link to clipboard
Copied
I hope then that very short solution (from edited part of my post) works also for OSX, but if not then maybe my first code from the same post would work too. I mean without killing cmd process (what is specific for Windows). If so the only code there is needed for OSX is that from reply number 10 of this theard? If someone can test it. please let us know how it works.
EDIT: I see many links on your site are broken. Do you plan to fix them?
Copy link to clipboard
Copied
>I see many links on your site are broken. Do you plan to fix them?
Somebody else said something similar. Which site and which links?
Copy link to clipboard
Copied
OMG I was sure I put the link - just try some. If you're lucky you get error: xtools​ for ex. these two:
Copy link to clipboard
Copied
The page ps-scripts.sourceforge.net/xtools.html was last edited in 2008 which was back in the CS2 era. I stopped updating because Adobe abandoned the HTML editor that I was using and I really didn't feel like learning a new one.
But the main problem here is that SourceForge is phasing out support for CVS. Looks like I'll have to move things over to Git.
The most immediate effect is that you can't browse for particulars in xtools via CVS which is what the links in xtool.html refer to.
You are stuck having to download a zip file rather than download a single .jsx file.
I guess this means I'll have to relearn Git and update my build scripts. I'll post on here when everything is ready.
Copy link to clipboard
Copied
I even didn't know we could use some Adobe HMTL editor. Probably there are more abandoned produtcs / tools they were useful but for some reason will be now on part of history. Thx for explanation. Anyway I like more old site, than modern Git.
Copy link to clipboard
Copied
Kukurykus​​, is this xtools really still working (with PS 2018)? Seems great, but hasn't been updated in the past 3 years....
Copy link to clipboard
Copied
That's the question to xbytor2​.
How do you like my new attempt? ie:
system('start http://adobe.com')
Copy link to clipboard
Copied
Kukurykus wrote:
How do you like my new attempt? ie:
system('start http://adobe.com')
Is start a Windows thing? If so, it could be:
function openURL(url) {
var open = $.os.match(/windows/i) ? 'start' : 'open';
system(open + " " + url);
}
Davide
Copy link to clipboard
Copied
Funny that was so easy, as earlier I tried more complex methods to do the same. xbytor2 wil be happy with OSX 'open'!
Copy link to clipboard
Copied
where do I put the link to open site?
Copy link to clipboard
Copied
openURL('http://adobe.com')