I work for a newspaper and am trying to create a very rudimentary system to integrate print with the web. Very, very rudimentary.
My idea is this:
All the articles on our website have an ID number, with a corresponding URL, so an article might be something like "http://www.ournewspaper.com/articles/83920". From there, there's an edit button you can click on (if you're logged in to edit the website), which will take you to the back end, where you enter all the metadata for the story (headline, author, image captions, related links, tags, etc.).
I was thinking of having each InCopy story linked to its corresponding article on the web, so that people could click on the story in the InDesign layout (either from InCopy or InDesign) and run a script which would give them the ID number of the story in our website's CMS. This ID number would be stored as a label of the Story object. Once the person who is editing the story has access to the web page for that same story, they can start typing in all that metadata, and after the paper has gone to print, they can upload the story itself (processed by another script I wrote).
If worst comes to worst, I could just have the script provide the user with the URL for the story, and they can cut and paste it into a browser window. But I have a feeling this will not make our editors happy.
So my question is: does anybody know a way we can have the script open a browser, and point it to the appropriate URL?
Also, if anyone knows of any cheap and simple solutions that have already been created along these lines, I'd be happy to hear them.
Thanks,
Richard Harrington
Sure that my fellow-scripters will provide a simple answer to your request!
(I really have no experience in app/url targetting from InDesign.)
However this snippet seems to work on WindowsXP.
function openInBrowser(/*str*/url)
{
var f = new File(Folder.temp.absoluteURI +
'/url_' + (+new Date()) + '.url' );
var fStr = "[InternetShortcut]\rURL="+url;
f.open('w');
f.write(fStr);
f.close();
f.execute();
f.remove();
}
// Test:
openInBrowser("http://www.indiscripts.com/");
The script simply creates a temporary URL Shortcut File and executes it. The default browser is launched and the web page is displayed.
@+
Marc
Here's Gerald Singelmann's function using your method which works both on Mac and Windows:
The adavntage of this approach is that it works event while InDesign is locked in a modal state...
function openWebsite(ws) {
if (File.fs == "Macintosh") {
var tempFile = File("~/Desktop/tempurl.webloc");
tempFile.open("w");
tempFile.write("<?xml version=\"1.0\" encoding=\"UTF-8\"?>\
<!DOCTYPE plist PUBLIC \"-//Apple//DTD PLIST 1.0//EN\" \"http://www.apple.com/DTDs/PropertyList-1.0.dtd\">\
<plist version=\"1.0\">\
<dict>\
<key>URL</key>\
<string>"+ ws +"</string>\
</dict>\
</plist>");
tempFile.close();
tempFile.execute();
for (var aux = 0; aux < 100; aux++) {
$.sleep(10);
}
tempFile.remove();
} else {
var tempFile = File("~/Desktop/cuppascript.url");
tempFile.open("w");
tempFile.write("[InternetShortcut]\rURL="+ws);
tempFile.close();
tempFile.execute();
for (var aux = 0; aux < 100; aux++) {
$.sleep(10);
}
tempFile.remove();
}
}
Harbs
This one, too, (due to Dave Saunders) is platform neutral. I doubt it will work if ID is locked in a modal state, but I whether that's an advantage I don't know.
Peter
function goToURL (theURL)
{
var aDoc = app.documents.add (false);
var myDest = aDoc.hyperlinkURLDestinations.add (theURL);
myDest.showDestination ();
aDoc.close (SaveOptions.no);
}
pkahrel wrote:
This one, too, (due to Dave Saunders) is platform neutral. I doubt it will work if ID is locked in a modal state, but I whether that's an advantage I don't know. (...)
Typically, Gerald's approach (modal state safe) allows to launch the browser from a ScriptUI dialog, while Dave's approach needs to invoke the InDesign DOM (create a ghost document, etc.) which fails within a modal dialog.
BTW, here's a factorized code:
function openInBrowser(/*str*/ url)
{
var isMac = (File.fs == "Macintosh"),
fName = 'tmp' + (+new Date()) + (isMac ? '.webloc' : '.url'),
fCode = isMac ?
('<?xml version="1.0" encoding="UTF-8"?>\r'+
'<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" '+
'"http://www.apple.com/DTDs/PropertyList-1.0.dtd">\r'+
'<plist version="1.0">\r'+
'<dict>\r'+
'\t<key>URL</key>\r'+
'\t<string>%url%</string>\r'+
'</dict>\r'+
'</plist>') :
'[InternetShortcut]\rURL=%url%\r';
var f = new File(Folder.temp.absoluteURI + '/' + fName);
if(! f.open('w') ) return false;
f.write(fCode.replace('%url%',url));
f.close();
f.execute();
$.sleep(500); // 500 ms timer
f.remove();
return true;
}
// Test:
openInBrowser("http://www.indiscripts.com/");
@+
Marc
[Harbs, why doesn't the syntax highlighter work anymore from FF?]
FWIW,
doScript() works in CS5 even when the app is in a modal state and I don't like writing files unnecessarily... ![]()
Here's the approach I use:
function GotoLink(url){
url = url || "http://in-tools.com";
if(kAppVersion>6){
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);
}
}
else {
linkJumper = File(Folder.temp.absoluteURI+"/link.html");
linkJumper.open("w");
var linkBody = '<html><head><META HTTP-EQUIV=Refresh CONTENT="0; URL='+url+'"></head><body> <p></body></html>'
linkJumper.write(linkBody);
linkJumper.close();
linkJumper.execute();
}
}
Marc Autret wrote:
[Harbs, why doesn't the syntax highlighter work anymore from FF?]
It works for me. How are you using it?
Harbs
Harbs' last script above works for me except for a couple of things:
1. What's kAppVersion, in line 3? My interpreter doesn't recognize that word. I changed that line to
if (+app.version[0] > 6) { // take first letter of version string, convert it to a number
and it works.
2. In the case of versions below 7, on the Mac, when you say
linkJumper.execute();
it opens the file in my text editor, which is what .html files are set to open with on my computer. Is there a way to force it to open in a web browser without using doScript, which will not open in a modal state?
This is an academic matter for me, as the typical user always has .html files set to open in browsers, and also everyone at my place of work is running CS5. But I'd be curious to know.
richardh6 wrote:
1. What's kAppVersion, in line 3? My interpreter doesn't recognize that word. I changed that line to
Sorry about that. I always initialize my script with a global variable for versioning purposes. My functions just assume that it's already been defined...
I intialize it like this:
kAppVersion = parseFloat(app.version);
2. In the case of versions below 7, on the Mac, when you say
linkJumper.execute();
it opens the file in my text editor, which is what .html files are set to open with on my computer. Is there a way to force it to open in a web browser without using doScript, which will not open in a modal state?
This is an academic matter for me, as the typical user always has .html files set to open in browsers, and also everyone at my place of work is running CS5. But I'd be curious to know.
Good point. That's another reason why Gerald's method of writing the files is better...
Harbs
I think this way is very easy.
I use a redirect javascript code.
var url = "http://forums.adobe.com/message/3180931";
//Example goToUrl(url);
function goToUrl(url){
var text='';
var file = "/temp.html";
file = new File(Folder.temp.absoluteURI+file);
file.encoding = "UTF-8"; file.open("w");
file.write(text);
file.close();
file.execute();
}
North America
Europe, Middle East and Africa
Asia Pacific