<?xml version="1.0" encoding="UTF-8"?><rss
version="2.0"
xmlns:content="http://purl.org/rss/1.0/modules/content/"
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/"
> <channel><title>Comments on: AppleScript: YUI Compression</title> <atom:link href="http://thinkclay.com/technology/applescript-yui-compression/feed" rel="self" type="application/rss+xml" /><link>http://thinkclay.com/technology/applescript-yui-compression</link> <description>Creative Media Design, Powered by Wordpress</description> <lastBuildDate>Mon, 21 May 2012 11:02:00 +0000</lastBuildDate> <sy:updatePeriod>hourly</sy:updatePeriod> <sy:updateFrequency>1</sy:updateFrequency> <generator>http://wordpress.org/?v=3.2.1</generator> <item><title>By: Sasasa</title><link>http://thinkclay.com/technology/applescript-yui-compression/comment-page-1#comment-2097</link> <dc:creator>Sasasa</dc:creator> <pubDate>Tue, 08 Nov 2011 07:15:00 +0000</pubDate> <guid
isPermaLink="false">http://thinkclay.com/?p=995#comment-2097</guid> <description>good.....</description> <content:encoded><![CDATA[<p>good&#8230;..</p> ]]></content:encoded> </item> <item><title>By: Aaron</title><link>http://thinkclay.com/technology/applescript-yui-compression/comment-page-1#comment-1892</link> <dc:creator>Aaron</dc:creator> <pubDate>Thu, 03 Mar 2011 01:16:00 +0000</pubDate> <guid
isPermaLink="false">http://thinkclay.com/?p=995#comment-1892</guid> <description>Hi there, great website design and much thanks for this script it really helped me get a jump start!
I was tweaking out on your code and I have it successfully adding the correct extension based on if it’s a .js or .css file (initially all files are saved with .js extension)
Also, the original code re-writes the file names with the original file extension still intact (eg. styles.css.min.css or scripts.js.min.js).  This is fixed now.  Here is the working code.
[code]
on run
tell application &quot;Finder&quot;
set this_item to choose file with prompt &quot;Choose CSS or JS file:&quot;
set dir to the selection as alias
set dir to container of dir as text
set ext to name extension of this_item
set newName to this_item as text
set newName to text 1 thru ((offset of &quot;.&quot; &amp; ext in newName) - 1) of newName
end tell
set newPath to posix_path(newName)
set mypath to posix_path(this_item)
set dirpath to posix_path(dir)
runCompression(mypath, dirpath, newPath, ext)
end run
on posix_path(mac_path)
set mac_path to (mac_path as text)
set root to (offset of &quot;:&quot; in mac_path)
set rootdisk to (characters 1 thru (root - 1) of mac_path)
tell application &quot;Finder&quot;
if (disk (rootdisk as string) is the startup disk) then
set unixpath to &quot;/&quot; &amp; (characters (root + 1) thru end of mac_path)
else
set unixpath to &quot;/Volumes:&quot; &amp; mac_path
end if
end tell
set chars to every character of unixpath
repeat with i from 2 to length of chars
if item i of chars as text is equal to &quot;/&quot; then
set item i of chars to &quot;:&quot;
else if item i of chars as text is equal to &quot;:&quot; then
set item i of chars to &quot;/&quot;
else if item i of chars as text is equal to &quot;&#039;&quot; then
set item i of chars to &quot;\&#039;&quot;
else if item i of chars as text is equal to &quot;&quot;&quot; then
set item i of chars to &quot;\&quot; &amp; &quot;&quot;&quot;
else if item i of chars as text is equal to &quot;*&quot; then
set item i of chars to &quot;\*&quot;
else if item i of chars as text is equal to &quot;?&quot; then
set item i of chars to &quot;\?&quot;
else if item i of chars as text is equal to &quot; &quot; then
set item i of chars to &quot;\ &quot;
else if item i of chars as text is equal to &quot;\&quot; then
set item i of chars to &quot;\\&quot;
end if
end repeat
return every item of chars as string
end posix_path
on runCompression(mypath, dirpath, newPath, ext)
tell application &quot;Terminal&quot;
do shell script &quot;java -jar &quot; &amp; dirpath &amp; &quot;yuicompressor-2.4.2.jar &quot; &amp; mypath &amp; &quot; -o &quot; &amp; newPath &amp; &quot;.min.&quot; &amp; ext
end tell
end runCompression  [/code]</description> <content:encoded><![CDATA[<p>Hi there, great website design and much thanks for this script it really helped me get a jump start!</p><p>I was tweaking out on your code and I have it successfully adding the correct extension based on if it’s a .js or .css file (initially all files are saved with .js extension)</p><p>Also, the original code re-writes the file names with the original file extension still intact (eg. styles.css.min.css or scripts.js.min.js).  This is fixed now.  Here is the working code.</p><p>[code]<br
/> on run<br
/> tell application "Finder"<br
/> set this_item to choose file with prompt "Choose CSS or JS file:"<br
/> set dir to the selection as alias<br
/> set dir to container of dir as text<br
/> set ext to name extension of this_item<br
/> set newName to this_item as text<br
/> set newName to text 1 thru ((offset of "." &amp; ext in newName) - 1) of newName</p><p> end tell<br
/> set newPath to posix_path(newName)<br
/> set mypath to posix_path(this_item)<br
/> set dirpath to posix_path(dir)</p><p> runCompression(mypath, dirpath, newPath, ext)<br
/> end run</p><p>on posix_path(mac_path)<br
/> set mac_path to (mac_path as text)<br
/> set root to (offset of ":" in mac_path)<br
/> set rootdisk to (characters 1 thru (root - 1) of mac_path)<br
/> tell application "Finder"<br
/> if (disk (rootdisk as string) is the startup disk) then<br
/> set unixpath to "/" &amp; (characters (root + 1) thru end of mac_path)<br
/> else<br
/> set unixpath to "/Volumes:" &amp; mac_path<br
/> end if<br
/> end tell<br
/> set chars to every character of unixpath<br
/> repeat with i from 2 to length of chars<br
/> if item i of chars as text is equal to "/" then<br
/> set item i of chars to ":"<br
/> else if item i of chars as text is equal to ":" then<br
/> set item i of chars to "/"<br
/> else if item i of chars as text is equal to "'" then<br
/> set item i of chars to "\'"<br
/> else if item i of chars as text is equal to """ then<br
/> set item i of chars to "\" &amp; """<br
/> else if item i of chars as text is equal to "*" then<br
/> set item i of chars to "\*"<br
/> else if item i of chars as text is equal to "?" then<br
/> set item i of chars to "\?"<br
/> else if item i of chars as text is equal to " " then<br
/> set item i of chars to "\ "<br
/> else if item i of chars as text is equal to "\" then<br
/> set item i of chars to "\\"<br
/> end if<br
/> end repeat<br
/> return every item of chars as string<br
/> end posix_path</p><p>on runCompression(mypath, dirpath, newPath, ext)<br
/> tell application "Terminal"<br
/> do shell script "java -jar " &amp; dirpath &amp; "yuicompressor-2.4.2.jar " &amp; mypath &amp; " -o " &amp; newPath &amp; ".min." &amp; ext<br
/> end tell<br
/> end runCompression  [/code]</p> ]]></content:encoded> </item> <item><title>By: Neil Maclean</title><link>http://thinkclay.com/technology/applescript-yui-compression/comment-page-1#comment-1685</link> <dc:creator>Neil Maclean</dc:creator> <pubDate>Mon, 20 Sep 2010 12:36:00 +0000</pubDate> <guid
isPermaLink="false">http://thinkclay.com/?p=995#comment-1685</guid> <description>This looks good, thanks very much. Could you do me a big favour and tell me how to use it? It&#039;s downloaded but I don&#039;t know what to do next.
Many thanks
Neil </description> <content:encoded><![CDATA[<p>This looks good, thanks very much. Could you do me a big favour and tell me how to use it? It&#8217;s downloaded but I don&#8217;t know what to do next.<br
/> Many thanks<br
/> Neil</p> ]]></content:encoded> </item> <item><title>By: BobMarche</title><link>http://thinkclay.com/technology/applescript-yui-compression/comment-page-1#comment-794</link> <dc:creator>BobMarche</dc:creator> <pubDate>Thu, 11 Jun 2009 02:49:20 +0000</pubDate> <guid
isPermaLink="false">http://thinkclay.com/?p=995#comment-794</guid> <description>Thanks for the useful info. It&#039;s so interesting</description> <content:encoded><![CDATA[<p>Thanks for the useful info. It&#8217;s so interesting</p> ]]></content:encoded> </item> <item><title>By: Geoff</title><link>http://thinkclay.com/technology/applescript-yui-compression/comment-page-1#comment-792</link> <dc:creator>Geoff</dc:creator> <pubDate>Wed, 10 Jun 2009 00:11:05 +0000</pubDate> <guid
isPermaLink="false">http://thinkclay.com/?p=995#comment-792</guid> <description>Hey, that&#039;s very helpful. I&#039;d been looking for something like this. I actually cobbled together a Perl script to compress certain raw JS files in my project prior to deployment, but this is a great, generally applicable solution. Thanks!
- geoff</description> <content:encoded><![CDATA[<p>Hey, that&#8217;s very helpful. I&#8217;d been looking for something like this. I actually cobbled together a Perl script to compress certain raw JS files in my project prior to deployment, but this is a great, generally applicable solution. Thanks!</p><p> &#8211; geoff</p> ]]></content:encoded> </item> </channel> </rss>
