1

I have a simple script

on run
    display dialog "Hello" buttons {"Ok"}
end run

I saved it as application (let's say myapp.app) If I just launch it from finder by double clicking then it works (i.e. shows the dialog box), but I want to use it for opening files.

The problem: For example I have file.xyz, then right-click it to "open with" and choose my.app. In this case my.app doesn't start (no icon at the dock panel, no dialog box shown).

1 Answer 1

2

You can use an open handler to drag items on the application like this:

on open of theFiles
    --  Executed when files are dropped on the application

    display dialog "There are " & (count of theFiles) & " files dropped" buttons {"OK"}
end open
Sign up to request clarification or add additional context in comments.

3 Comments

I was curious about your using the word "of" as part of the "on open" handler. So I checked the applescript language guide (ALG) and it's not part of the handler name. For those interested, you can open the ALG from the help menu of AppleScript Editor. It's in the section "About Handlers->Handlers in Script Applications->open Handlers".
pg 144 of the Definitive guide talks about the of Prepositional Parameter. It made its way into one of my template and I never removed it because it sounds more English-like.
Dragging is good, but now I need to implement "open with". Is it possible? It's strange that the applescript application closes right after starting it.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.