• 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: Mon, 28 Sep 2009 11:06:47 -0700
  • Thread-topic: AS Application

on 9/28/09 9:52 AM, Stockly, Ed at email@hidden wrote:

> I don't see a "save as dialog" in your script, so I'm not sure what you're
> referring to, but if the "path to me" is not returning the correct path, it
> may be the context the script is running in.

I thought I had included it since Yvan had replied. I've not yet had a
chance to implement his suggestions but here is the code as I have it now.

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)
        set pathToThisApp to POSIX path of (path to me) as text

        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 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
originalPathAndFile) & " 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


>
> If it's running from inside an application, via a script menu, then "me" may
> be a reference to the application, rather than the script itself and path to
> me would return the alias of the Application.  If you save the script as an
> applet that should resolve the issue.
>
> HTH,
>
> ES
>
>
> On 09/28/09 6:45 AM, "Steffan A. Cline"  wrote:
>
>> Aside from the file chooser not allowing anything issue under Swedish
>> localized OS, I came across another issue. My code seems to NOT be always
>> drawing the correct original path in the save as dialog. If the app opens
>> and saves the file with no user interaction, it works fine. This issue
>> happened with another user under Swedish localization.
>
>  _______________________________________________
> 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



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

References: 
 >Re: AS Application (From: "Stockly, Ed" <email@hidden>)

  • Prev by Date: Re: Disappearing Mail Trash
  • Next by Date: Re: Choose Folder
  • Previous by thread: Re: AS Application
  • Next by thread: Re: AS Application
  • Index(es):
    • Date
    • Thread