• 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: "Steffan A. Cline" <email@hidden>
  • Date: Sat, 26 Sep 2009 18:29:11 -0700
  • Thread-topic: AS Application

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

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

on handle(filelist)
    repeat with i in filelist
        set i to i as alias
        tell application "Finder" to set filename to the POSIX path of i
        set myArray to my theSplit(filename, ".")
        set ext to item (count myArray) of myArray as string
        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 prefix to items 1 thru ((count myArray) - 1) of myArray
        set newname to join(prefix) & "min." & ext
        set myPath to POSIX path of (path to me) as text
        set command 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 command
            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 handle

on open filelist
    handle(filelist)
end open

on theSplit(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 theSplit

on join(theArray)
    set out to ""
    repeat with i in theArray
        set out to out & i & "."
    end repeat
    return out
end join




on 9/26/09 4:13 PM, Philip Aker at email@hidden wrote:

> On 2009-09-26, at 14:44:36, Steffan A. Cline wrote:
>
>>>> Why don't you just write the 'command" to a file to see what the cumulative
>>>> lines look like. If it looks correct, then another possibility is the
>>>> permissions of the files involved. Also, put your code in a 'try', 'on
>>>> error', 'end try' block and log any caught errors to a file.
>
>>> I found the error I was making and fixed it but am now playing with error
>>> trapping. I am trying to capture the result of the error so I can format it
>>> my way.
>
>>> set theResult to (do shell script command)
>
>>> This does not work. If it succeeds then it's ok. If there is an error, I can
>>> use the "on error" but the actual error is not contained within theResult.
>>> Is there a way around this?
>
>> Google is your friend.
>>
>> on error errorMsg
>>     do something with errorMsg
>
> You can also get an error number for trapped errors. So:
>
> try
> --doit()
> on error errs number errn
> display dialog errs & return & return & "Error code: " & (errn as text)
> default button "OK" with icon stop
> return -- the return value may be anything appropriate for your application
> end try
>
>
>> Is there a way to set a scrollable area for the output rather than a tall
>> dialog?
>
> You will have to move to AppleScript Objective-C and Interface Builder to
> customize dialogs.
> For 'display dialog' a cheap trick is to pad your string result with spaces
> and returns.
>
>
> Philip Aker
> echo email@hidden@nl | tr a-z@. p-za-o.@
>
> Democracy: Two wolves and a sheep voting on lunch.
>
>



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

  • Follow-Ups:
    • Re: AS Application
      • From: "email@hidden" <email@hidden>
References: 
 >Re: AS Application (From: Philip Aker <email@hidden>)

  • Prev by Date: Re: Add Printer via UI scripting
  • Next by Date: Re: AS Application
  • Previous by thread: Re: AS Application
  • Next by thread: Re: AS Application
  • Index(es):
    • Date
    • Thread