Re: AS Application
Re: AS Application
- Subject: Re: AS Application
- From: "Steffan A. Cline" <email@hidden>
- Date: Sun, 27 Sep 2009 09:17:06 -0700
- Thread-topic: AS Application
Ok. Something ugly here. When I test the script locally, it works fine. I
sent it to a friend in Sweden and on his machine, it's not recognizing the
allowed file types when the open dialog comes up. Everything is grayed out.
It will not allow him to select either css or js which are clearly defined
as allowed.
Anyone seen this?
I suppose a work around would be to allow any file and then just filter it
within the script. Seems a hoakie way to do it.
on 9/27/09 12:34 AM, Steffan Cline at email@hidden wrote:
> Thanks Ed!
>
> Funny thing is I had invested a few hours into it before you replied. This
> is what I have come up with so far. It's longer than yours but fancier. I am
> able to vary the output and functionality quite a bit. Let me know what you
> think.
>
> property allowedFileTypes : {"js", "css"}
>
> minimizeFiles(choose file with prompt "Select a .js or .css file to be
> minimzed." of type allowedFileTypes with multiple selections allowed)
>
> on open filelist
> minimizeFiles(filelist)
> end open
>
> on minimizeFiles(filelist)
> repeat with i in filelist
> set originalPathAndFile to the POSIX path of (i as alias)
>
> tell application "Finder" to set ext to name extension of i
> if ext is not in allowedFileTypes then
> display dialog "The extension " & quoted form of ext & " is not
> supported by the YUI compressor." with icon stop buttons "Bummer!" default
> button 1
> exit repeat
> end if
>
> set pathToThisApp to POSIX path of (path to me) as text
>
> set originalPath to split(originalPathAndFile, "/")
> set originalPath to join((items 1 thru ((count originalPath) - 1) of
> originalPath), "/")
>
> set originalFile to getFileName(originalPathAndFile)
>
> set newFile to split(originalFile, ".")
> set newFile to join((items 1 thru ((count newFile) - 1) of newFile),
> ".") & "min." & ext
>
> set newPathAndFile to originalPath & newFile
>
> try
> tell application "Finder" to if exists newPathAndFile as POSIX
> file then set newPathAndFile to POSIX path of ¬
> (choose file name with prompt "The default name for the
> minimized file is taken. Please choose another name." default location
> originalPath default name newFile)
> set newFile to getFileName(newPathAndFile)
> end try
>
> set command to "java -jar " & (quoted form of (pathToThisApp &
> "Contents/Resources/yuicompressor-2.4.2.jar")) & " " & (quoted form of
> originalPathAndFile) & ¬
> " -o " & (quoted form of newPathAndFile) & " --charset utf-8"
>
> try
> do shell script command
> display dialog "The file " & (quoted form of originalFile) & "
> has been successfully minified. " & return & return & "The new file is
> called " & (quoted form of newFile) ¬
> with icon alias ((path to me) &
> "Contents:Resources:yahoo.icns" as string) buttons "Awesome!" default button
> 1
> on error errorMsg
> display dialog "The file " & (quoted form of pathAndFile) & "
> could not be minified because the following error(s) occurred:" default
> answer errorMsg ¬
> with icon stop buttons "Bummer!" default button 1
> end try
> end repeat
> end minimizeFiles
>
> on split(theString, theDelimiter)
> -- save delimiters to restore old settings
> set oldDelimiters to AppleScript's text item delimiters
> -- set delimiters to delimiter to be used
> set AppleScript's text item delimiters to theDelimiter
> -- create the array
> set theArray to every text item of theString
> -- restore the old setting
> set AppleScript's text item delimiters to oldDelimiters
> -- return the result
> return theArray
> end split
>
> on join(theArray, theDelimiter)
> set out to ""
> repeat with i in theArray
> set out to out & i & theDelimiter
> end repeat
> return out
> end join
>
> on getFileName(x)
> set x to split(x, "/")
> set x to item (count x) of x
> return x
> end getFileName
>
>
>
> on 9/26/09 11:31 PM, email@hidden at email@hidden wrote:
>
>>
>> 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
>
Thanks
Steffan
---------------------------------------------------------------
T E L 6 0 2 . 7 9 3 . 0 0 1 4 | F A X 6 0 2 . 9 7 1 . 1 6 9 4
Steffan A. Cline
email@hidden Phoenix, Az
http://www.ExecuChoice.net USA
AIM : SteffanC ICQ : 57234309
YAHOO : Steffan_Cline MSN : email@hidden
GOOGLE: Steffan.Cline Lasso Partner Alliance Member
---------------------------------------------------------------
_______________________________________________
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