• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag
 

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: AS Application
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: AS Application


  • Subject: Re: AS Application
  • From: "email@hidden" <email@hidden>
  • Date: Sat, 26 Sep 2009 23:31:31 -0700


On Sep 26, 2009, at 6:29pm, Steffan A. Cline wrote:

Ok. Here it is. It's working well. If anyone has suggestions for
optimization, I'm all ears.


This is pretty good work, below is a slightly modified version...

You don't need to coerce i to an alias, both choose file and on open return a list of aliases

You can use a single file command to get the file extension.

You can use the & to concatenate the new file name.

You don't need to put the posix path coercion in a Finder tell, and, they say, it's better without the tell.

HTH,

ES

MinimizeFiles(choose file with prompt "Select a .js or .css file to be minimzed." of type {"js", "css"} with multiple selections allowed)

on MinimizeFiles(filelist)
repeat with i in filelist
tell application "Finder" to set ext to name extension of i
if ext is not in {"js", "css"} then
display dialog "The extension " & quoted form of ext & " is not supported by the YUI compressor." with icon stop buttons "Damn!"
exit repeat
end if
set oldDelims to AppleScript's text item delimiters
set AppleScript's text item delimiters to {"." & ext}
set filename to the POSIX path of i --Finder tell not needed
set newname to text item 1 of filename & ".min." & ext
set AppleScript's text item delimiters to oldDelims
set myPath to POSIX path of (path to me) as text
set javaJarCommand to "java -jar " & (quoted form of (myPath & "Contents/Resources/yuicompressor-2.4.2.jar")) & ¬
" " & (quoted form of filename) & " -o " & (quoted form of newname) & " --charset utf-8"
try
do shell script javaJarCommand
display dialog "The file " & (quoted form of filename) & " has been successfully minified. " & return & return & "The saved file is called" & (quoted form of newname) buttons "Awesome!"
on error errorMsg
display dialog "The file " & (quoted form of filename) & " could not be minified because the following error(s) occurred:" default answer errorMsg with icon stop buttons "Damn!"
end try
end repeat
end MinimizeFiles


on open filelist
 MinimizeFiles(filelist)
end open




_______________________________________________ Do not post admin requests to the list. They will be ignored. AppleScript-Users mailing list (email@hidden) Help/Unsubscribe/Update your Subscription: Archives: http://lists.apple.com/archives/applescript-users

This email sent to email@hidden
  • Follow-Ups:
    • Re: AS Application
      • From: "Steffan A. Cline" <email@hidden>
References: 
 >Re: AS Application (From: "Steffan A. Cline" <email@hidden>)

  • Prev by Date: Re: AS Application
  • Next by Date: Re: Manipulating text
  • Previous by thread: Re: AS Application
  • Next by thread: Re: AS Application
  • Index(es):
    • Date
    • Thread