Jon
Jon

Reputation: 757

Beginner: Make Applescript app into Service

Objective

I want to be able to run the Applescript to open multiple applications using a shortcut. To do this, I would like to create a Service using Automator (I've done this for opening one application, the script opens multiple). After some research, I found that I need to make the script an action in Automator, using Xcode.

Progress

I have this Applescript app that does what I want:

--Insert apps to open here:
set multApp to {"Safari", "Mail"}

set noOfApplications to count of multApp
set itemNum to 1
repeat with counter from 1 to noOfApplications
    openApp(item itemNum of multApp)
    set itemNum to itemNum + 1
end repeat

on openApp(chosenApplication)
    tell application chosenApplication to activate
end openApp

I am a beginner at all 3 (haven't touched Xcode)

What I've done in Xcode is: started on the main.xib (as per a tutorial) and have used Interface Builder (v. 3.2.6) to have 3 "pop up buttons" that I want to bind to Applications.

Questions

  1. Is this the right method? Am I using Xcode correctly?

  2. How to bind to an application? What input to "Controller Key", "Model Key Path" etc...

  3. Is there a way to see the workings behind a current action (like "Launch Application")

Final Notes

This is more for learning than for actually using the script. So I know I can just add more "Launch Application" to the current Service. I want to know so I can make any Applescript app (script) into a Service... Wouldn't it be handy?

Sorry for my noob-ness (let me know if the question is unclear), and THANKS for any advice!

UPDATE: "Run Applescript" action will do the job, ignore Xcode (Thanks @regulus6633) and just make Service with that action.

Upvotes: 1

Views: 1350

Answers (1)

regulus6633
regulus6633

Reputation: 19030

Jon said: After some research, I found that I need to make the script an action in Automator, using Xcode.

Not sure what research told you that. You're making this much more complex than is necessary. It will take a long time to learn everything required to do what you want using xcode. I'd suggest staying with applescript and automator for now. Once you master them then get into xcode stuff. In general when you use xcode you're programming in objective-c, so at a minimum you have to learn some objective-c before you will be successful.

So sticking with applescript for now, the closest thing you can get to a popup button with menu choices is the choose-from-list applescript command. Your best bet would be to use something like the following. And if you want to make it a service then use automator to create the service and run the applescript code in that.

set applicationsList to {"Safari", "TextEdit", "Mail"}

-- choose one or more applications
choose from list applicationsList with title "Application Launcher" with prompt "Choose the applications..." OK button name "Launch" cancel button name "Quit" with multiple selections allowed
tell result
    if it is false then error number -128 -- cancel
    set theApplications to items
end tell

-- launch the chosen applications
repeat with i from 1 to count of theApplications
    tell application (item i of theApplications) to activate
end repeat

Upvotes: 3

Related Questions