Studio project: click button to open new window

quick question(s)

  1. how do you open up a new window by clicking on a button (or any way)

  2. how do you get a script to use a variable inputted by the user into a text box or radio buttons? (google search type thing)

  3. how do you get a script to hide the apps it’s doing its buisness in?

  4. is it possible to have static text display a property of sorts (eg. whether the modem is connected, if a certain program is oped)

thanks

Or… not…

Most, if not all, of these questions can be answered by looking at the AppleScript Studio sample projects that are included when you install the Developers’ tools.

Jon

I did, but I copied the script and it didn’t work. I figured out the window one, though. Go me!

Help would be appriciated though…

If you couldn’t find the answers in the demo projects included with Developer’s Tools, then searching the forums (fora for sticklers) would have helped. For instance, hiding apps has been covered many, many times.

This should help:

on clicked the_object
    --1. how do you open up a new window by clicking on a button (or any way) 
    show window "window name"
    
    --2. how do you get a script to use a variable inputted by the user into a text box or radio buttons? (google search type thing) 
    set the_variable to contents of text field "text field name" of window "main" as string
    
    --3. how do you get a script to hide the apps it's doing its buisness in? 
    --Um, what? Do you mean how to hide apps?
    tell application "System Events" to set visible of every process whose visible is true to false
    
    --4. is it possible to have static text display a property of sorts (eg. whether the modem is connected, if a certain program is oped) 
    tell application "System Events" to set open_apps to name of every process
    if open_apps contains "iTunes" then
        set the_string to "iTunes is running."
    else
        set the_string to "iTunes is not running."
    end if
    set contents of text field "static text field" of window "main" to the_string
end clicked

Jon


[This script was automatically tagged for color coded syntax by Convert Script to Markup Code]

Thank you! That’s very helpful. I’ll poke around the Xcode tools folder so I don’t have to ask stupid questions next time.

The Google thing went according to plan, except for the fact that the script no longer works when the text box is placed inside a tab. I tried using “tab view” and all kinds of things. Sorry about the stupid question (again).

Really, look at the sample projects included with the Developer’s Tools, the answers truly are there. You can use either the name or the index of the elements you need to target. This example uses the index so it gets the value from the first text field of the view of the first tab item of the first tab view of the main window:

on clicked the_object
    set the_variable to contents of text field 1 of view of tab view item 1 of tab view 1 of window "main" as string
end clicked

Jon

Okay, I searched the forum and the applescript dictionaries before posting this one… How do i get a progress bar to animate indeterminately? also, how do i make parts of a script “trigger” a percentage on the progress bar. basically, how do progress bars work?

also, is there a way to package in a “helper” program inside an app that can be launched by script?

thanks, i know i’m a pain in the AppleScriptStudio

Perhaps you just don’t understand how the search function works. Search for all terms: “progress bar” (no quotes) and restrict the search to the AppleScript Studio forum. Seek and ye shall find.

Yes, just drag the app into the resources folder in the Groups & Files pane of Xcode/Project Builder and make sure to check that it is copied to the project. When you build your project as an app, the helper app will be included in the resource folder of the bundle and you can access it via the path to your project: ((path to me as string) & “Resources:Helper,app”).

Jon

I did that, but i get the error “Application is not running.” Which, of course, it isn’t…

What is it that you did?

Jon

on clicked theObject
	open application ((path to me as string) & "Contents:Resources:whackapig.app")
end clicked

I also tried this with just “Resources:whackapig.app” and “Contents:Resources:whackapig” and “Resources:whackapig” and as

on clicked theObject
	open ((path to me as string) & "Contents:Resources:whackapig.app")
end clicked

I tried all the variations I could think of…

This should work but somehow Xcode is modifying the app when it includes it in the bundle. If the helper app is added to the bundle after it is built (choose “show contents” from the Finder for the bundle and then copy your helper app to the resources folder), then this code works:

on clicked the_object
    set helper_path to ((path to me as alias) as string) & "Contents:Resources:helper.app"
    tell application "Finder" to open (helper_path as alias)
end clicked

Jon

Okay, another series of things, this time slightly more complicated.

Alright, I’ve got myself a drawer and a text box that is kind of like the calculator “paper tape” and a script that randomizes things and puts them in a text field in the main window. Anyway, I need to (a) place the text from my other script into the “paper tape”, and keep adding to it every time a new combination is generated. (b) I’d like to also be able to export the contents of the text box as a .txt or .rtf or some type of text file at the push of a button. Also it would be good to have an export window to allow people to choose a location for said text file, preferably in a sheet.

Thanks a million.

P.S. The developer tools examples are usually overcomplicated for what I want to do, and the Xcode help is hellish, and everyone here seems to know what’s going on, so if the questions seem ignorant or something, sorry.

You can see this thread for a handler to add/clear a text view used as a log, it may be of use. You can also look at some of the projects on my site:

[url=http://homepage.mac.com/jonn8/as/]http://homepage.mac.com/jonn8/as/[/url]

especially:

[url=http://homepage.mac.com/jonn8/as/dist/Installerish.hqx]http://homepage.mac.com/jonn8/as/dist/Installerish.hqx[/url]

or

[url=http://homepage.mac.com/jonn8/as/dist/Landmine.hqx]http://homepage.mac.com/jonn8/as/dist/Landmine.hqx[/url]

Jon

I’ve figured out the log thing, now the main thing I need to know is how do I get that text box to export to a file? Also, what is the “path” to a drawer? (how do i get the script to know the object i want it to use is in the drawer?) i’ve tried view name and drawer name and all manner of things.

edit: i figured out the path thing, now i just need the saving part

edit: actually my path thing didnt work!! i looked at the examples. here’s what i got:

	set contents of text field "log" of drawer "drawer" of window "main" to MegaPhrase

Supa Puerco, Have you done the tutorials yet?

I did the tutorials before starting on my first ASS app (actually I got about half way through the mail search one :wink: ) and I have to say I wouldn’t have known where to start if I hadn’t!!
they cover all of the basics and I found them very informative…

give them a go, I’m sure you will learn a lot of usefull stuff.

you can finde them by pasting this link into your broweser (assuming you have developer tools at the root level of your main HD):

file:///Developer/Documentation/AppleScript/Conceptual/StudioBuildingApps/index.html#//apple_ref/doc/uid/TP30000889

actually, since i posted that i figured it out, but my main question now is why the save panel isnt working for me



on clicked theObject
	tell save panel
		set title to "Hey!"
		set prompt to "Save Dammit"
		set required file type to "txt"
		set treat packages as directories to false
	end tell
	display save panel in directory "~" attached to window "main"
end clicked

on panel ended theObject with result withResult
	if withResult is 1 then
		set savepath to path name of save panel
		set the_file to savepath as file specification
		set the_data to "it worked"
		try
			open for access the_file with write permission
			set eof of the_file to 0
			write (the_data) to the_file starting at eof
			close access the_file
		on error
			try
				close access the_file
			end try
		end try
	else
		set contents of text field "path name" of window "main" to ""
	end if
end panel ended