On 03 Sep 2014, at 20:51, Jeroen van de Ven <[email protected]> wrote:

> Hi,
> 
> I've been struggling to get my first script working, to do some stuff when a 
> document is saved. This is what I have so far, and below it the error that 
> arises. What's going on?
> 
> using terms from application "BBEdit"
> 
> on documentDidSave(docinfo)
> 
> set docpath to POSIX path of file of docinfo
> 
> do shell script "ls " & quoted form of docpath
> 
> end documentDidSave
> 
> end using terms from

If you make a run handler for the script, you can test everything in the script 
editor, and actually see which event returns the wrong result, and how to get 
the desired result.

I’ve split up the script, and because we are running from the script editor, we 
have to be a bit more explicit as to whom we’re talking to.

on docSave(docinfo)
    tell application "BBEdit"
        set docpath to POSIX path of file of docinfo
        -- return file of docinfo
        -- set docpath to (POSIX path of ((file of docinfo) as alias))
    end tell
    tell application "Terminal"
        activate
        do script "ls " & quoted form of docpath
    end tell
end docSave

using terms from application "BBEdit"
    on documentDidSave(docinfo)
        docSave(docinfo)
    end documentDidSave
end using terms from

on run
    tell application "BBEdit" to set docinfo to document 1 of window 1
    tell me to docSave(docinfo)
end run

-- End of script 

When we run this, we see where things go wrong, and then suggestions what we 
need to inspect follow naturally: If we execute the first commented line we see 
that we get a file object. Apparently this does not know about POSIX paths 
(although the StandardAdditions dictionary says otherwise). However, if you 
turn the file object into an alias (second comment), then the POSIX path will 
do its magic.

Keep in mind that the do shell script command is limited, and that the output 
may not be available in an obvious way. 

Maarten

Attachment: smime.p7s
Description: S/MIME cryptographic signature

Reply via email to