<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>mim.Armand &#187; Adobe extend-script</title>
	<atom:link href="http://armand.eu/blog/tag/adobe-extend-script/feed/" rel="self" type="application/rss+xml" />
	<link>http://armand.eu/blog</link>
	<description>Artist, inventor and developer!</description>
	<lastBuildDate>Wed, 24 Jun 2015 12:02:08 +0000</lastBuildDate>
	<language>en-US</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=4.2.2</generator>
	<item>
		<title>manage paths in Adobe Extend-Script</title>
		<link>http://armand.eu/blog/manage-paths-in-adobe-extend-script/</link>
		<comments>http://armand.eu/blog/manage-paths-in-adobe-extend-script/#comments</comments>
		<pubDate>Wed, 25 Jun 2014 18:45:45 +0000</pubDate>
		<dc:creator><![CDATA[mim]]></dc:creator>
				<category><![CDATA[Adobe ExtendScript]]></category>
		<category><![CDATA[dev]]></category>
		<category><![CDATA[Absolute path]]></category>
		<category><![CDATA[Adobe CS]]></category>
		<category><![CDATA[Adobe extend-script]]></category>
		<category><![CDATA[AES]]></category>
		<category><![CDATA[development]]></category>
		<category><![CDATA[InDesign]]></category>
		<category><![CDATA[Javascript]]></category>
		<category><![CDATA[Paths]]></category>
		<category><![CDATA[plugin]]></category>
		<category><![CDATA[Relative path]]></category>
		<category><![CDATA[scripting]]></category>

		<guid isPermaLink="false">http://armand.eu/blog/?p=62</guid>
		<description><![CDATA[Managing paths obtained from Adobe Extend-Script, Specially when you want to share these paths with an external 3th application (to do things which aren&#8217;t possible with just ExtendScript) is kind of difficult! For instance let&#8217;s say we want to get the Path of an In-Design file being opened (and in front) in in-Design, we may &#8230; <a href="http://armand.eu/blog/manage-paths-in-adobe-extend-script/" class="more-link">Continue reading <span class="screen-reader-text">manage paths in Adobe Extend-Script</span> <span class="meta-nav">&#8594;</span></a>]]></description>
				<content:encoded><![CDATA[<figure id="attachment_66" style="width: 674px;" class="wp-caption aligncenter"><a href="http://armand.eu/blog/wp-content/uploads/2014/06/Header_cs_sdk_brnd_ex.jpg"><img class="size-full wp-image-66" src="http://armand.eu/blog/wp-content/uploads/2014/06/Header_cs_sdk_brnd_ex.jpg" alt="Adobe Exten-Script (source: internet)" width="674" height="208" /></a><figcaption class="wp-caption-text">Adobe Exten-Script (source: internet)</figcaption></figure>
<p>Managing paths obtained from Adobe Extend-Script, Specially when you want to share these paths with an external 3th application (to do things which aren&#8217;t possible with just ExtendScript) is kind of difficult!<br />
For instance let&#8217;s say we want to get the Path of an In-Design file being opened (and in front) in in-Design, we may simply do:</p>
<p><script src="https://gist.github.com/mim-Armand/10bf1ff8483dc5d7ad5c.js"></script><br />
 And get:</p>
<figure id="attachment_63" style="width: 299px;" class="wp-caption aligncenter"><a href="http://armand.eu/blog/wp-content/uploads/2014/06/AES_path_01.jpg"><img class="size-full wp-image-63" src="http://armand.eu/blog/wp-content/uploads/2014/06/AES_path_01.jpg" alt="alert(app.activeDocument.filePath);" width="299" height="181" /></a><figcaption class="wp-caption-text">alert(app.activeDocument.filePath);</figcaption></figure>
<p>But there is obviously 3 (+1 not obvious here!) possible problems with this path (even if you can transfer that variable as easily as shout it out in an alert! <small>look at #3</small>):</p>
<ol>
<li>the Tilde (<a title="Tilde on Wikipedia!" href="http://en.wikipedia.org/wiki/Tilde" target="_blank"><code>~</code></a>) character at the beginning, an environment variable meaning &#8220;<a title="Home Directory Path" href="http://en.wikipedia.org/wiki/Home_directory" target="_blank">Home Directory</a>&#8220;, which is not a recognizable standard character in all the different programing environments (for instance it&#8217;d be <a title="Batch parameters" href="http://www.microsoft.com/resources/documentation/windows/xp/all/proddocs/en-us/percent.mspx?mfr=true" target="_blank"><code>%~dp0</code></a> in <a title="Windows Batch Scripting" href="http://en.wikibooks.org/wiki/Windows_Batch_Scripting" target="_blank">Batch scripting</a> and <code><a title="System Properties in Java" href="http://docs.oracle.com/javase/tutorial/essential/environment/sysprop.html" target="_blank">user.home</a></code>, (<a title="Bug # 4787391 (mostly Windows Fault than Java!)" href="http://bugs.java.com/bugdatabase/view_bug.do?bug_id=4787931" target="_blank">more or less!</a>) in Java) although it is supposed to be the absolute path using above code!</li>
<li>existence of Slash characters (<a title="Slash character" href="http://en.wikipedia.org/wiki/Slash_%28punctuation%29" target="_blank"><code>/</code></a>) in the path instead of Backslash (<a title="Backslash character" href="http://en.wikipedia.org/wiki/Backslash" target="_blank"><code>\</code></a>), making it hard (not so much tho!) to send it through a <a title="JSON (JavaScript Object Notation)" href="http://json.org/" target="_blank">JSON</a> package for example (or save it in a <a title="Batch File" href="http://en.wikipedia.org/wiki/Batch_file" target="_blank">batch file</a> -again- for instance), be-cause in most environments it&#8217;d be considered as a <a title="Escape characters" href="http://en.wikipedia.org/wiki/Escape_character" target="_blank">escape character</a> and not a path level separator.</li>
<li>It is an object and not a string (apparently!) and you can send, save or sometimes even use the <a title="myPath var in the above Gist" href="https://gist.github.com/mim-Armand/10bf1ff8483dc5d7ad5c#file-aes_path_01-jsx" target="_blank"><code>myPath</code> </a>variable for instance directly! (it will give you an <code>[object]</code> instead of the path, <small>which I <b>guess</b> should be the parent <code>File object</code> itself</small>)</li>
<li>in addition if our file wasn&#8217;t in our Desktop folder and was in a disk drive instead, we would have this problem too:
<figure id="attachment_64" style="width: 164px;" class="wp-caption aligncenter"><a href="http://armand.eu/blog/wp-content/uploads/2014/06/AES_path_02.jpg"><img class="size-full wp-image-64" src="http://armand.eu/blog/wp-content/uploads/2014/06/AES_path_02.jpg" alt="alert(app.activeDocument.filePath);" width="164" height="181" /></a><figcaption class="wp-caption-text">alert(app.activeDocument.filePath);</figcaption></figure>
<p>as you can see, an additional Slash character (<a title="Slash character" href="http://en.wikipedia.org/wiki/Slash_%28punctuation%29" target="_blank"><code>/</code></a>) before the Drive letter (c)! which is incomprehensible to me why it is!! but it seems that Extend-Script itself doesn&#8217;t have any problem with it, but as I said when you want o communicate with 3th party apps it will become a problem immediately!
</li>
<p>    So as you may guess there is a lot of solutions for any and each of mentioned problems, but here I just wanted to suggest the most convenient one I figured out after trying a lot of different shenanigan techniques!<script src="https://gist.github.com/mim-Armand/1124e39b165172f1129e.js"></script><br />
Here we used <a title="Regulra expressions" href="https://developer.mozilla.org/en/docs/Web/JavaScript/Guide/Regular_Expressions" target="_blank">Regular Expression</a> Patterns to <a title="str.replace(regexp|substr, newSubStr|function[,flags]);" href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/replace" target="_blank"><code>Replace()</code></a> all (by using the <code>g</code> pseudo) the Slashes with Backslashes and by using <a title="Look at the references for fsName!" href="http://www.jongware.com/idjshelp.html" target="_blank"><code>fsName</code> </a>instead of <a title="look at the references for filePath!" href="http://www.jongware.com/idjshelp.html" target="_blank"><code>filePath</code> </a>eliminating other problems (like getting &#8220;relative paths&#8221; (or fake absolutes!) instead of absolutes and the beginning slash character)<br />
And the result:</p>
<figure id="attachment_65" style="width: 398px;" class="wp-caption aligncenter"><a href="http://armand.eu/blog/wp-content/uploads/2014/06/AES_path_03.jpg"><img class="size-full wp-image-65" src="http://armand.eu/blog/wp-content/uploads/2014/06/AES_path_03.jpg" alt="alert(app.activeDocument.fullName.parent.fsName).toString().replace(/\\/g, '/');" width="398" height="180" /></a><figcaption class="wp-caption-text">alert(app.activeDocument.fullName.parent.fsName).toString().replace(/\\/g, &#8216;/&#8217;);</figcaption></figure>
<p>Awesome! <img src="http://s.w.org/images/core/emoji/72x72/1f600.png" alt="😀" class="wp-smiley" style="height: 1em; max-height: 1em;" /><br />
<small>Please let me know if you have a better idea to this or if you see a problem or something, I appreciate it <img src="http://s.w.org/images/core/emoji/72x72/1f609.png" alt="😉" class="wp-smiley" style="height: 1em; max-height: 1em;" /></small><br />
mim,</p>
]]></content:encoded>
			<wfw:commentRss>http://armand.eu/blog/manage-paths-in-adobe-extend-script/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
	</channel>
</rss>
