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

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
pppfff

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!
pppfff

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.

Cheers,

Craig

See above:

		set theFrame to textField's frame()

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

|redColor|

Sweet! Had not thought of that!

Shane,
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
pppfff

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.

Shane,

thank you again. It is working ! :slight_smile:

Have added it before the “set {{x:x1 …” line

tell textField to setFrameSize_({200, 100})
set theFrame to textField’s frame()
set {{x:x1, y:y1}, {width:theWidth2, height:theHeight2}} to theFrame as list

Step by step I am learning, baby steps !

Is it ok to ask another question (or more :wink: ?

How can make the text field scrolling, if the content is too long ?
Or how can I make the font smaller if it is too long ?

best regards
pppfff

I would consider a text view.

As Richard said, you want an NSTextView rather than an NSTextField.

hmmh, two answers an I still have difficulties to find the right object. Sorry!
In the Library I am finding only TextView which is “NSTextView in an NSScrollView”, but it is not working for me.

Is there something I am overlooking ?

thank you
pppfff

Make sure you IB link goes to the top of the text view, there will be a thinner separate box at the top, this is the actual text view, the rest is a scroll view.

And as in my tutorial and other examples, the 2 key methods are |string|() and setString() rather than stringValue() and setStringValue()

wow, that was very quick!
And I see now the text. Great!
If the text is longer than the text box I am able to scroll.

It is not scrolling automatically from left to right.
I guess I have to show you what I want to do.
Will create some pictures and post it here.

Very very good forum here !

THANK YOU, Richard, Shane, Craig and all!
pppfff

Or a link to the zipped project folder, you have Mobile Me? Or any file sharing site.

Yes, I have MobileMe and I am just uploading a screenshot movie to demonstrate what the application is doing.
The movie is 36 MB and my upload speed is very very slow. It takes 20 minutes, could be even more and it is quite late here in Germany.
Tomorrow I will post the link to my public MobileMe folder.
Next step is then to upload the zipped project folder.
Sorry for the delay.
best regards
pppfff

OK,
here the link to the demonstration how the application is working:
Video

And inside the application I have written:

– Have used two Applescripts as “templates” to realize this application

– No 1
(*
Applescript Code for this Image View is mainly
from:
“Art to Desktop” for iTunes
written by Doug Adams
dougadams@mac.com
v2.1 sept 10 2009
– updated for Snow Leopard compatibility
– enhancements and finesses

(there are additions from myself, to view all images in the artist folder as well)
*)


– No 2
(*
db iTunes Fade-and-Advance
By David Battino, Batmosphere.com
Version 2009-03-03JJ
Based on ideas from Doug’s AppleScripts and Mac OS Hints

See [url=http://www.oreillynet.com/mac/blog/2007/03/itunes_fadeout_script.html]www.oreillynet.com/mac/blog/2007/03/itunes_fadeout_script.html[/url] for background

or 
http://broadcast.oreilly.com/2009/05/itunes-dj-applescript-fade-to.html

This script fades out iTunes if it's playing and then plays the next song.
If iTunes is paused, the script will start playback.
*)

(*
And here I have found very good tipps & tricks

Slider Control
Mouse Control
Color control

http://www.bynkii.com/archives/mac-os-x-scripts/2009/

Craig Williams has created 5 very good tutorial about the new Xcode Applescript

http://macscripter.net/viewforum.php?id=31

Infos about the Idle Function you will find here:
http://discussions.apple.com/thread....7699&tstart=45

And here the link where I have found how to display a picture:
http://macscripter.net/viewtopic.php?id=30462

The buttons have been designed and created by myself with Photoshop 6.0

*)

And again I have a question:
How is it posssible to this text in the ABOUT or HELP popup, to give credit to all who has helped?

best regards
pppfff

I don’t know how but you could too easily add a credits item to the app name menu with a window with a text view.

Hi Richard,
yes, that was my thought as well, but I wanted to have it “professional” :slight_smile:

Here the link to project source code.
Zipped Project Files

You need to have jpg or png pictures in the iTunes artist folder.
If it is a compilation then it is looking in the artist folder as well.
If you press the button “Open/create Artist folder …” then the finder is checking if such a folder exists.
If yes, it opens this folder. If no, it creates such a folder.
Then Safari is searching for the artist name in google pictures medium size.
Now you can open the full size picture and drag it to the artist folder.
Update: Goal is to automate that step. With a confirmation step to make sure the picture is the the right one.

The skip forward button with an S skips to the selected song in iTunes.
All the other buttons fade in and out to the next or previous song.

Have fun and please give feedback!

best regards
pppfff