Thanks, Mike for reminding me,
However, how to open/execute an url? I have not found any clue on that.
The following definetely does not work:
app.AllowNewFileURL = true; // has no effect at all
var url = File ("http://www.daube.ch");
url.execute (); // => false
url.open (); // => false
The word "url" is not very present in the documentaion of ES (Scripting Guide ). Most occurrences are in the legalese text. Relevant notes are not helpful for my problem:
- escape(aString) , unescape(aString), fileName.absolueURI, fileName.getRelativeURI(basePath)
- Constants.FA_Note_URL, Constants.FP_InsetURL, Constants.FP_ServerUrl, Constants.FV_URL_CHECKED_IN, Constants.FV_URL_CHECKED_OUT, Constants.FP_AllowNewFileURL, FCodes.KBD_BROWSE_URL.
- app.AllowNewFileURL: When True, allows usage of file:/ and file: URLs for referring to a file.
In FDK the note is: If True, allows file URLs starting with “file:” as well. Otherwise, only file URLs starting with file:// are allowed. - Functions for the CMS handling
- FDK: WebDav handling
The following works:
var url = File ("file://e:/_DDDprojects/FM-calc/test-scripts/OpenPDFatNamedDestination.pdf");
url.execute ();
But this does not open the PDF at all:
var url = File ("file://e:/_DDDprojects/FM-calc/test-scripts/OpenPDFatNamedDestination.pdf#page=10");
url.execute ();
Even this does not work:
var url1 = File ("http://www.daube.ch/docu/files/etb-customising-fm12.pdf");
url1.execute ();
IMHO this is a mess!
Well, friends, I have found a solution at StackOverflow.com: In German we say fur such a solution "von hinten druch die brust geschossen".
ExtendScript:
// Open PDF at named destination
var theFile = "PDFwithDestination.pdf"; // for my case: in same path as this script
var destination = "M8.newlink.FMcalcseries" // needs to be found in pdf, because the 8 is not a constant
OpenPdfAtDestination (theFile, destination);
function OpenPdfAtDestination (pdfFile, namedDestination) { // ====================================
var path = GetScriptPath () + "\\";
var location = "nameddest=" + namedDestination; // see "Parameters for Opening PDF Files"
// Call OpenPdfWithParameters, according to
// http://stackoverflow.com/questions/20862868/file-execute-is-not-executing-my-script-how-to-debug-this-issue/20863131#20863131
// A workaround to pass arguments is to create another file, that calls this script with arguments.
// Yawar 2015-03-15
// Create the calling batch file
var tempFile = File (path + "tempScript.bat");
tempFile.open("w");
tempFile.encoding = "UTF-8";
tempFile.writeln (path + "OpenPdfWithparameters.exe " + '/A ' + location + ' "' + path + pdfFile + '"');
tempFile.close();
tempFile.execute ();
tempFile.delete;
}
function GetScriptPath () { //=====================================================================
// Get the script path
// Returns path in the function
var scrPath, newPath, winPath, lastBSlash;
// $.fileName: script path (including the file-name of the script)
// platform independent format e.g. /e/_DDDprojects/FM+EN-escript/escript
scrPath = $.fileName;
winPath = new File (scrPath);
scrPath = winPath.fsName; // get Windows format
lastBSlash = scrPath.lastIndexOf("\\"); // \ needs escaping
scrPath = scrPath.substring(0, lastBSlash);
return scrPath; // no final \ !
} // --- end GetScriptPath
AutoHotKey script - must be converted to an exe file:
; OpenPdfWithParameters.ahk
; 2016-04-15 Klaus Daube
; Get the arguments from the caller (works only in compiled version!)
parmList =
Loop, %0% ; For each parameter:
{
param := %A_Index%
parmList = %parmList% `n%param%
}
; MsgBox, Number of parameters: %0%`n%parmList%
; let's find the relevant application
RegRead, sDefaultApp, HKCR, .pdf
RegRead, sDefaultAct, HKCR, %sDefaultApp%\shell
RegRead, sDefaultCommand, HKCR, %sDefaultApp%\shell\%sDefaultAct%\command
StringTrimRight, command, sDefaultCommand, 5 ; remove the "%1"
; MsgBox %command% ; "H:\Adobe\Acrobat11\Acrobat\Acrobat.exe"
; open the pdf with the parameters according to "Parameters for Opening PDF Files"
Run, %command% %parmList%
This works, however a flicker is created due to the batch file execution.