Newbie needs help

Is there a simple way to take a script, place it in studio, and create a GUI for it and make it work? I know that is asking a lot but I just need a simple fix. Thanks a lot!

The only “lot” your asking for is for us to magically know everything you’re trying to do without you actually telling us. There are hundreds, if not thousands, of scripts you could be trying to create a front-end for so I’m not sure we can be of much help without some more details.

It is fairly simple to create gui’s for plain scripts, but there are a lot of interface elements and design techniques that will dictate the kind and quantity of help we can provide. Perhaps you could give some idea of what you’re trying to do, what obstacles or error’s your getting, and maybe post some of your code if applicable.

I haven’t got my mind-readers license yet, so you’ll have to be a bit more forthcoming with the details. 8)

j

Simple? If what you want something like an input dialog for a script, a few hours spent going over the tutorials in “Building Applications with Applescript Studio” should get you on your way. (should be on your drive, Developer/Documentation/Applescript/Conceptual/).

ok say i just want to add a menu. Where would I place my script so that i can build off of it?

Do you mean a menu in a window in an application… or a menu in the menu bar of the finder (an ‘NSStatusItem’)? These are two totally different things, the latter of which is definitely out of your range right now given the tone and depth of your requests.

When you come in and make such broad statements, it is really difficult to have any idea what you’re after. We simply can not provide for you given these criteria. Your first post might as well have asked…

Spend some time looking around and clarifying to yourself what you want, and then ask for help. You’ll get a lot more answers that way… especially constructive ones. I also agree with bryanh in that you should spend some time picking apart the extras that apple shipped with xcode, especially the example apps (/Developer/Examples/Applescript Studio/), as they are a good, basic starting point for learning ASStudio. Once you know what you’re looking for, you can post or search here at macscripter for interactive help. You can also search the apple developer website for information about everything applescript. Searches like “applescript menu” or “NSStatusItem” will get you to the official documentation for the objects you’re working with.

Keep truckin… you’ll get it. :smiley:
j

Sorry :oops: !
Lets see if I can give a little more help or at least make the question easier to understand. Situation: I have a script written and would like to expand on it by adding a UI in xcode. Where would I place my basic script to start to build off of it. Where would the sole of the app be? OR Situation 2: I would like to write a app using the applescript language in xcode. I would do everything and then have the main window. Where would I start to write the app? Does that make sense?

Since you haven’t given ANY details, I’ll just make up a set of circumstances and provide one possible method of integrating and enhancing the script in an xcode applescript project. Let’s say we have a basic applescript that says…

on run
	set targetUser to "jobu"
	set currentUser to system attribute "USER"
	set isMatch to false
	if currentUser is equal to targetUser then set isMatch to true
	return isMatch
end run

We’ll make an interface with one window, in which a button pressed will get some input from one text field, and display whether the text entered matches the name of the current user in another text field.

  1. Open xcode and select File > New Project. Name it whatever… i.e. “MyApp”.
  2. When the project is created, a list of project files titled “Groups & Files” on the left will have two important groups… “Scripts” and “Resources”. Expand “Resources” and then double-click on “MainMenu.nib”. This will launch Interface Builder (IB) and open up the default interface file (NIB).
  3. By default, one window will be created. Select “Tools > Show Info” or press (cmd+shift+i) to open the info window. Detailed information and options for whatever object is currently selected will show in the info window.
  4. Click once on the default window to make sure it’s selected, and then select “Applescript” (cmd+7) from the drop-down menu in the info window. In the name field, enter a name by which you’ll reference the window in your script (i.e. “theWindow”).
  5. From the palettes window (the one with all of the interface elements in it) drag two text fields (NSTextField, not a NSTextView) and a button to your window in that order. Using the same process as the window, select each object and give it an applescript name (i.e. “targetUser”, “theOutput”, and “theButton”). While in the applescript info pane for the button, check the box “Action > Clicked” and select the application’s script at the bottom (i.e. “MyApp.applescript”). Then click the “Edit Script” button. This will take you back to xcode, and will insert an empty ‘clicked’ handler to the script.
  6. In the applescript, inside the newly created clicked handler enter your code between the “on clicked…” and “end clicked” lines. Now this is where the process gets more complex, and where I had hoped you’d actually provide some HELP by providing some of your code. Using our extremely simple example, I would modify the original code and insert it in the handler as below, in order to send the data to the interface…
on clicked theObject
	if name of theObject is "theButton" then
		(* Tell block; one method of referencing an object *)
		tell window "theWindow"
			set targetUser to contents of text field "targetUser"
		end tell
		set currentUser to system attribute "USER"

		set isMatch to false --> Default to false
		if currentUser is equal to targetUser then set isMatch to true
		
		(* Full path to object; another method of referencing an object *)
		set contents of text field "theOutput" of window "theWindow" to (isMatch as string)
	end if
end clicked

As I said a couple times now, I have no idea what you’re trying to do, so this is merely a simple tutorial on how to manage the nib file and it’s objects, how to connect those objects to your scripts, how to receive the events from the interface, and how to integrate and alter basic applescript code to fit into an xcode applescript application.

:rolleyes:,
j