[TxMt] TextMate vs Applescript

Dr. Drang drdrang at gmail.com
Tue Mar 18 14:34:06 UTC 2008


On Mon, Mar 17, 2008 at 11:22 PM, pascal at g <ymostudio at gmail.com> wrote:
> I am having difficulties implementing your suggestions, not having enough
> knowledge of the Applescript syntax; I mainly do html and css coding, and
> have adapted a script to my needs.

You've put my two lines after the wrong 'tell application "Finder"'. I
should have been more explicit in my message--electrons are cheap.
Here is a script that does what your script wants to do:

    -- get the base folder
    set theFolder to choose folder with prompt "Create/Choose Client
Project folder"

    -- get the Briefs subfolder, making it if it doesn't already exist
    try
        set briefFolder to ((theFolder as text) & "Brief") as alias
    on error
        tell application "Finder" to set briefFolder to (make new
folder at theFolder with properties {name:"Brief"}) as alias
    end try

    -- ensure that a set of subfolders exists
    try
        get ((theFolder as text) & "Captures") as alias
    on error
        tell application "Finder" to make new folder at theFolder with
properties {name:"Captures"}
    end try
    try
        set processedFolder to ((theFolder as text) & "Processed") as alias
    on error
        tell application "Finder" to set processedFolder to (make new
folder at theFolder with properties {name:"Processed"}) as alias
    end try
    try
        get ((processedFolder as text) & "Hi-Res Images") as alias
    on error
        tell application "Finder" to make new folder at
processedFolder with properties {name:"Hi-Res Images"}
    end try
    try
        get ((processedFolder as text) & "Low-Res Images") as alias
    on error
        tell application "Finder" to make new folder at
processedFolder with properties {name:"Low-Res Images"}
    end try
    try
        get ((theFolder as text) & "Trash") as alias
    on error
        tell application "Finder" to make new folder at theFolder with
properties {name:"Trash"}
    end try

    -- make a new file in the Briefs subfolder and open it in TextMate
    set briefDoc to (POSIX path of briefFolder) & "$.tasks"
    do shell script ("touch " & briefDoc & "; open -a TextMate " & briefDoc)


This may be unnecessarily verbose, but the 'try/on error' clauses will
allow it to work regardless of whether the subfolders already exist.
Your script assumes that "Captures," "Processed," etc. do not exist
and will fail if they do.

I've also changed the shell script in the last line. Most people on
this list will have the "mate" shell command available, but a newcomer
may not.

Hope this works for you.

-- 
Dr. Drang



More information about the textmate mailing list