I love Apple, but they messed up big...

I love Apple. I have had only Apple computers since I was little, and many of their upgrades have taken some getting used to… like, when iMovie changed in the version after iMovie HD. But all of the change have been somehow understadable… All of their changes except for their newest one. They messed up Applescript Studio. They did not just change it, and make the interface different, they flat out removed it from Xcode 3.2 . Now it is some Obj-C/Applescript crap. I don’t want to learn a new language to program in, I want to do the same thing I used to do, which was copy and paste a huge chunk from applescript to XCode… what the hell?

Believe it or not, that’s what many of us are doing. The code that drives other apps is virtually unchanged; it’s only the interface code that’s different.

Ok fine. You can still copy/paste applescript code… but the interface code (I guess that is what I was referring to) is very different. How the heck does it work?

A month ago I didn’t know what the underscore meant now I’ve created these:
http://files.me.com/imadrichard/v9b3la -app
http://files.me.com/imadrichard/ppaiha -project (zipped 2.9 MB, 5 MB when unzipped)

I was in the same position but trusted Apple like everyone always should, Apple was right to do what they did. There are simple basics to learn and it’s almost no different.

Very well. The lack of documentation is a problem, but you’ll find quite a few example projects mentioned around here – check them out.

Some things are simpler than ASStudio, some are harder, and many are only possible with ASObjC.

ok, I’ll take ur word for it, i hope ur right, and ASOBJC is easy to learn… It’s ok if u can’t/don’t want to, but can u direct me to a good (group or one) example project that is easy, and demonstrates a lot of the concepts, bcuz if u learned yourself, you will know where a good place to begin is

A lot of good stuff has been posted around here. There’s a sample project and explanatory movie at http://www.macosxautomation.com/applescript/develop/. Further example projects and details have been posted at http://www.scriptingmatters.com/ASObjC, http://allancraig.net/blog/ and http://www.tidbits.com/matt/.

Ok. Simple project. To learn how the language works, I tried to make a very VERY simple program (that would have been a joke in AS). I tried to make a program that has a button and two textfields. The user can fill one of the fields, and then he/she pushes the button. The text from textfield1 (input by the user) is then copied into textfield2.

So what code have you written so far?

well, everytime I write new code, it never seems to have the same result… Well, I can like, have a button that, when clicked, displays a dialog with a string literal in it… Not a variable…

Perhaps the code at the bottom of http://macscripter.net/viewtopic.php?id=30898 would help, a little multiplier, with more variables, more interface but nothing in the code more than you should already know from writing dialogs.

First, Thank you for giving all such good advice and examples!

I am new in Apple (4 month) , Applescript (2 month) and have started with Xcode after SnowLeopard.
Have bought the book Applescript Studio Programming for absolute beginners and found that it is worthless now :frowning:

Shane mentioned the link to www.macosxautomation.com/applescript/develop , this was the link I have found as well and after that I was able to create my first working application some days ago.

I am struggling that there is no documentation, Have found the same method Richard mentioned in one of his posts (The tutorial) , to check the XCode help and then translate.
That was working after a lot of try and errors with the rotate text function = setFrameRotation (see code below)
but it is not working with the color setting and the position setting of text boxes.
The only thing which is working 50% is the setFrameOrigin_ ,but here my hope is to use x,y parameters, but I have not found a solution.

Is there really no documentation for ASOC ?
Do you have examples for Changing the color of Text, button, windows, moving the text boxes, buttons ?

best regards

script RotateTestAppDelegate

property parent : class "NSObject"
property NSImage : class "NSImage" of current application
property textField : missing value
property ButtonPlus : missing value
property ButtonMinus : missing value
property ButtonTextEffect : missing value

property Angle : 90.0
property Inc : 10.0
on applicationWillFinishLaunching_(aNotification)
	tell textField to setFrameRotation_(90.0)
end applicationWillFinishLaunching_

on applicationShouldTerminate_(sender)
	-- Insert code here to do any housekeeping before your application quits 
	return true
end applicationShouldTerminate_

on ViewTextPlus_(sender)
	set Angle to Angle + Inc
	tell textField to setFrameRotation_(Angle)
	tell textField to setStringValue_(("Plus") as string)
end ViewTextPlus_

on ViewTextMinus_(sender)
	set Angle to Angle - Inc
	tell textField to setFrameRotation_(Angle)
	tell textField to setStringValue_(("Minus") as string)
end ViewTextMinus_

on ViewTextEffect_(sender)
	--tell textField to setFrameOrigin_(100) 
          -- working: But what Parameters do I need to place it not only in the left down corner 

	--tell textField to setBackgroundColor_(RedColor) -- not working

	tell textField to setStringValue_(("Effect") as string)
end ViewTextEffect_

end script

The frame coordinates are based on the coordinates of the containing view, with the bottom left being {0,0}. The Y value refers to the bottom of the view. So to put a text field in the bottom left of its window:

		tell textField to setFrameOrigin_({0, 0})

To put it top right, you’d do something like this:

		-- get window's frame
		set theFrame to textField's |window|()'s frame()
		-- allow for title bar
		set theFrame to textField's |window|()'s contentRectForFrameRect_(theFrame)
		set {{x:x1, y:y1}, {width:theWidth, height:theHeight}} to theFrame as list
		-- get textField's frame
		set theFrame to textField's frame()
		set {{x:x1, y:y1}, {width:theWidth2, height:theHeight2}} to theFrame as list
		-- move textField to top right
		tell textField to setFrameOrigin_({theWidth - theWidth2, theHeight - theHeight2})

Apart from the release notes, at this stage no.

Moving is done by setFrameOrigin_. You can set the color like this:

		set redColor to current application's class "NSColor"'s redColor() -- case matters; no cap R
		set otherColor to current application's class "NSColor"'s colorWithCalibratedRed_green_blue_alpha_(0, 1, 0, 1)
		tell textField to setBackgroundColor_(redColor)
		tell textField to setTextColor_(otherColor)
		tell mainWindow to setBackgroundColor_(redColor)

Thank you very much Shane !

All is working now … except the color Red! :slight_smile:
First the color change was not working at all, but good that you mentioned the caps is important.
My xcode has changes the redColor() to RedColor() automatically and after I tried blue all was ok.
No idea why this happen on my Mac.

With your examples it was even possible for me to change the size of the text box with the command:

tell textField to setFrameSize_({400, 50})

Now I am puzzeling how to find query other sizes like Text Box size.
Have tried with : set theTextboxSize to textField’s |FrameSize|()'s frame()

but no luck.

thank you again!

This has to do with how the compiler saves variable names in AppleScript. Once you compile using one variable name,
all future names will be capitalized the same. Really irritating. I believe the reason it is done this way
is so once you have one variable name, you can type the next one in all lowercase and it will reformat it letting
you know that you spelled it correctly.

The way around this is to remove all instances of the specified name from the file. Save and close the
project. When you open it back up, insert the correct name and compile.



See above:

		set theFrame to textField's frame()

Or if you can’t be bothered, surround the name in pipes:


Sweet! Had not thought of that!

I understand :slight_smile:

Being able to read can be an advantage!

Now I see the dimension of the text box. In the example below, I get two times the same results, even the size has been changed.
Is there a kind of update command I have to use?

best regards

tell textField to setFrameSize_({200, 100})

	set {{x:x1, y:y1}, {width:theWidth2, height:theHeight2}} to theFrame as list
	display dialog theWidth2
	display dialog theHeight2
	delay 2
	tell textField to setFrameSize_({400, 100})
	set {{x:x1, y:y1}, {width:theWidth2, height:theHeight2}} to theFrame as list
	display dialog theWidth2
	display dialog theHeight2

PS: Thank you Craig for the hint with the pipe symbols !
Do not need to buy a puzzle game, have it all here :slight_smile:

You haven’t updated the value of theFrame – you need a " set theFrame to textField’s frame()" after you change it.