Compiler Bug? Please help me I'm very confused...

Hi,

I’m not new to Applescript (1 1/2 years experience) but totally new to Xcode and Applescript Studio (1 month experience)
So I started a useless Application which controls iTunes to learn Xcode.
I call the App “iTunes Remote”.
After a short period I understood the syntax of Applescript Studio. Everything worked fine, until…
I found a bug in my Application. I made my Application look like that:
http://img103.imagevenue.com/view.php?image=20367_Bild_1_122_671lo.jpg

edit: lol? why do I get linked to a woman posing in front of a scary movie ad? /edit

(I got UNO installed so don’t wonder about the grey color)

I wanted the PlayPause Button to change to Play when iTunes is paused, or to Pause when iTunes is playing.
So I added a “if” which gets started when the PlayPause button is getting pressed.
It looks like this:


		tell application "iTunes" to set player_state to player state as string
		if player_state is "playing" then
			tell application "iTunes"
				pause
			end tell
		else if player_state is "paused" then
			tell application "iTunes" to play
		end if

player_state is made a global var at the beginning of the script.
I know that that doesn’t change the title of the button, but it should Play/Pause iTunes already

Then I have another Problem: I want to check the title of the RepeatButton to Off/One/All reliable to the state of iTunes:


on readitunes()
	--shuffle state:
	tell application "iTunes" to set shuffle_set to (shuffle of (current playlist)) as boolean
	--repeat state
	tell application "iTunes" to set repeatset to (song repeat of (current playlist)) as string
	--volume:
	tell application "iTunes" to set cur_vol to (sound volume)
end readitunes

on setGUI()
	--für shuffle:
	set contents of button "shuffle" of window "main" to shuffle_set
	--für volume:
	set contents of slider "volumeslider" of window "main" to cur_vol
	--für repeat:
	if repeatset is "off" then
		set title of button "repeat" of window "main" to "Off"
	else if repeatset is "one" then
		set title of button "repeat" of window "main" to "One"
	else if repeatset is "all" then
		set title of button "repeat" of window "main" to "All"
	end if
end setGUI

readitunes() and setGUI() are recalled in the “on launched theObject” handler.
the variables are made global at the beginning of the script.

In the “normal” script editor (shipped with the original system Installation) that works so fine.
In Xcode it doesn’t. :expressionless:
The strange is, that the setting of the volume (look above) does work.

So i thought: “Damned, where did I do the mistake?”
I searched like a nerd…and then I noticed that EVERYTHING works fine if I run that App in debug mode inside of Xcode.
Everything works the way I want it to.
So I’m very confused why it doesn’t work in normal way.

Could it be, that that is a bug made by Apple and the compiler? I think so.

If you think that it isn’t a bug, could you please help me? That would be very kind of you.
If needed I can post more sourcecode.

so far,

ShowGetter

Model: PowerMac G4
AppleScript: Xcode: 2.4.1 Applescript: 1.10.7
Browser: Safari 522.12.1
Operating System: Mac OS X (10.4)

Try something like this:

tell application "iTunes"
	playpause
	set player_state to player state as Unicode text
end tell

Hmmm I’m getting the same result with that.
In the “normal” mode it doesn’t work, but when I run it in Debug mode it works.:frowning:

Shall I post the hole Script so you can look what I did wrong?

Anyway, I think it is a Bug in the Compiler. How could I report it to Apple?

Hi,

This is a wild guess and you’re probably at it already. Question - is your button activated in the AppleScript pane and the “clicked” action checked? Sometimes, we do forget such simple things and start looking at even bigger issues. Please check.

I too am wondering what your problem is. Will take a look at the other issues and see what I come up.

Good luck.

archseed :slight_smile:

Hi,

Now, here’s a follow up to my earlier post about checking on your problems with shuffle and repeat of iTunes. I have a program (iTunes Manager in scriptbuilders) that checks these iTunes’ properties and I know that the codes work (see below). I have provided the codes for the shuffle and repeat properties separately but they are homologous in a sense and can actually be integrated.



using terms from application "iTunes"
	tell application "iTunes"
		set activePlaylist to the current playlist
		if shuffle of the activePlaylist is false then
			set shuffle of the activePlaylist to true
			my on_theShuffleButtonState()
		else 
			set shuffle of the activePlaylist to false
			my off_theShuffleButtonState()
		end if
	end tell
end using terms from

using terms from application "iTunes"
	tell application "iTunes"
		set activePlaylist to the current playlist
		if song repeat of the activePlaylist is off then
			set song repeat of the activePlaylist to all
			my all_theRepeatButtonState()
		else
			set song repeat of the activePlaylist to off
			my off_theRepeatButtonState()
		end if
	end tell
end using terms from

to on_theShuffleButtonState()
	tell window "main" to set the state of button "toggleShuffle" to 1
end on_theShuffleButtonState


to off_theShuffleButtonState()
	tell window "main" to set the state of button "toggleShuffle" to 0
end off_theShuffleButtonState


to all_theRepeatButtonState()
	tell window "main" to set the state of button "toggleRepeat" to 1
end all_theRepeatButtonState


to off_theRepeatButtonState()
	tell window "main" to set the state of button "toggleRepeat" to 0
end off_theRepeatButtonState 



I hope the above codes give you some guidance.

Good luck!

archseed :slight_smile:

Hi ShowGetter,

Sorry, I did not quite understand your problem with shuffle and repeat. I should have read more carefully.

Please disregard my previous long post on that unless you can extract something out of it.

Will continue to look into your issues and let you know.

Regrets.

archseed.

Hi,

Here I am again.

I did check the Xcode documentation and it seems that your referencing of the “title” property of the buttons is correct. Theoretically, there should be no problem changing the button titles.

The only thing I can think of, if this is not a bug at all, is whether you have iTunes active at on launch before you reference the objects in it. Not seeing your codes makes it very difficult to tell otherwise. Yes, I know, it is a simple thing, but like I said sometimes our problems are too simple and we tend to overlook them.

So, at the risk of being repetitive, please check your on launch handler and make sure that iTunes is active before you tell it to do something in your codes. This is the only thing I can think of.

Good luck.

archseed :slight_smile:

Firstly Thank you VERY much for your help :slight_smile:

The checkbox “action” in Interfacebuilder is activated.
And iTunes must be opened. Otherwise it won’t work. That problem do I want to solve later.

Thank you for the code. But before I’ll try that code I’ll upgrade to Xcode tools Version 2.5
If that won’t help (what I think will happen) I’ll try to insert your code.
For your code I have a question relying to that “my” tag which you inserted there.
What does it do? Does it link to the “to” tags?
If yes, should linking be always done that way?
Remenber that this is my first “not-hello-world-App” made with Xcode :wink:

And because I think it would be better for you to understand what I did, here’s my source:

-- iTunes Remote.applescript
-- iTunes Remote

--  Created by David on 30.09.07.
--  Copyright 2007 ShowGetter. All rights reserved.


--settings:
property fade : true
--others:
property windowOpened : false
property newvolume : "100"
property playingnow : "Titel"

--Diese Variablen global (also für alles geltend) machen:
global shuffle_set
global repeatset
global cur_vol
global player_state


--wird beim start aufgerufen. Settings auslesen.
on will finish launching theObject
	set windowOpened to false
	
end will finish launching

--beim start:
on launched theObject
	if windowOpened is false then
		showWindow()
	end if
	titelanzeige()
	readitunes()
	setGUI()
	if repeatset is "off" then
		set title of button "repeat" of window "main" to ("Off")
	else if repeatset is "one" then
		set title of button "repeat" of window "main" to ("One")
	else if repeatset is "all" then
		set title of button "repeat" of window "main" to ("All")
	end if
end launched

--button wird angeklickt:
on clicked theObject
	--playbutton got pressed:
	if name of theObject is "PlayButton" then
		getSettingsFromUI()
		titelanzeige()
		playpause()
		
		--titlebar got pressed (it looks like a normla text but it is a button withoiut frame)
	else if the name of theObject is "title" then
		titelanzeige()
		
		--nextbutton:
	else if the name of theObject is "next" then
		tell application "iTunes"
			next track
		end tell
		titelanzeige()
		
		--backbutton:
	else if the name of theObject is "back" then
		tell application "iTunes"
			back track
		end tell
		titelanzeige()
		
		--shuffle checkbox:
	else if the name of theObject is "shuffle" then
		tell application "iTunes"
			if shuffle of (current playlist) is true then
				tell (current playlist)
					set shuffle to false
				end tell
			else if shuffle of (current playlist) is false then
				tell (current playlist)
					set shuffle to true
				end tell
			end if
		end tell
		
	else if the name of theObject is "repeat" then
		song_repeat()
	end if
end clicked

on awake from nib theObject
	(*Add your script here.*)
end awake from nib

--before opening:
on open theObject
	titelanzeize()
end open

--the volumeslider:
on action theObject
	if name of theObject is "volumeslider" then
		set newvolume to contents of slider "volumeslider" of window "main" as integer
		tell application "iTunes" to set sound volume to newvolume
	else if the name of theObject is "titlebutton" then
		titelanzeige()
	end if
end action

--ask for current Title and show it:
on titelanzeige()
	tell application "iTunes" to set playingname to (name of current track) as string
	tell application "iTunes" to set playingartist to (artist of current track) as string
	set playingnow to playingname & " - " & playingartist
	set title of button "titlebutton" of box "box" of window "main" to playingnow
end titelanzeige

--show the window:
on showWindow()
	tell window "main"
		set visible to true
	end tell
	set windowOpened to true
end showWindow

-- set Shuffle:
on setshuffle()
	tell application "iTunes"
		if shuffle of (current playlist) is true then
			tell (current playlist)
				set shuffle to false
			end tell
		else if shuffle of (current playlist) is false then
			tell (current playlist)
				set shuffle to true
			end tell
		end if
	end tell
end setshuffle

--read settings:
on getSettingsFromUI()
	tell window "main"
		(*tell box "buttonbox"*)
		set fade to (state of button "fade") as boolean
		(*end tell*)
	end tell
end getSettingsFromUI

--Playbutton got pressed:
on playpause()
	--don't Fade:
	if fade is false then
		
		(* ++++++++++++++ That is the part where I don't know what doesn't work +++++++++++++ *)
		
		tell application "iTunes"
			playpause
			set player_state to player state as Unicode text
		end tell
		if player_state is "paused" then
			display dialog "paused"
		end if
		--Fade aktiviert:
	else if fade is true then
		tell window "main"
			set visible of progress indicator "progressindicator" to true
			tell progress indicator "progressindicator" to start
			
			(* ++++++++++++ That uses the same technic but it DOES work ++++++++++ *)
			
			--Fade:
			tell application "iTunes"
				if player state is (playing) then
					set sound_volume to sound volume
					set fader to sound_volume
					repeat while fader is greater than 0
						set sound volume to fader
						set fader to fader - 1
					end repeat
					pause
					tell application "iTunes Remote"
						tell window "main" to set title of button "PlayButton" to "Play"
					end tell
				else if player state is (paused) then
					play
					set sound_volume to sound volume
					set fader to sound_volume
					repeat while fader is less than 100
						set sound volume to fader
						set fader to fader + 1
					end repeat
					tell application "iTunes Remote"
						tell window "main" to set title of button "PlayButton" to "Pause"
					end tell
				end if
			end tell
			tell progress indicator "progressindicator" to stop
			set visible of progress indicator "progressindicator" to false
		end tell
	end if
	titelanzeige()
end playpause

--Repeat button got pressed:
on song_repeat()
	if title of button "repeat" of window "main" is "Off" then
		tell application "iTunes"
			tell (current playlist)
				set song repeat to one
			end tell
		end tell
		set title of button "repeat" of window "main" to "One"
	else if title of button "repeat" of window "main" is "One" then
		tell application "iTunes"
			tell (current playlist)
				set song repeat to all
			end tell
		end tell
		set title of button "repeat" of window "main" to "All"
	else if title of button "repeat" of window "main" is "All" then
		tell application "iTunes"
			tell (current playlist)
				set song repeat to off
			end tell
		end tell
		set title of button "repeat" of window "main" to "Off"
	end if
end song_repeat

--read setings from iTunes:
on readitunes()
	--shuffle state:
	tell application "iTunes" to set shuffle_set to (shuffle of (current playlist)) as boolean
	--repeat state
	tell application "iTunes" to set repeatset to (song repeat of (current playlist)) as string
	--volume:
	tell application "iTunes" to set cur_vol to (sound volume)
end readitunes

--transfer settings from readitunes to gui:
on setGUI()
	--für shuffle:
	set contents of button "shuffle" of window "main" to shuffle_set
	--für volume:
	set contents of slider "volumeslider" of window "main" to cur_vol
	--für repeat:
	if repeatset is "off" then
		set title of button "repeat" of window "main" to "Off"
	else if repeatset is "one" then
		set title of button "repeat" of window "main" to "One"
	else if repeatset is "all" then
		set title of button "repeat" of window "main" to "All"
	end if
end setGUI

Do you or someone find the Bug? (Remember: Started in Debug mode it works properly :/)

btw: Excuse me for my not perfect english. I’m german :slight_smile:

Just a suggestion:

tell application "iTunes"
	tell current playlist
		set shuffle to (not shuffle)
	end tell
end tell

Set shuffle to the opposite of the current value by using not (i.e. boolean negation operator).

No, you don’t understand what I mean.
I want the App to change the button to state of iTunes settings.
So If iTunes is launched and Repeat of one Song is on, then I want
iTunes Remote to change the Repeat button to “One”.
If all songs get repeated, I want it to change to “All” and os on.:wink:
It works if I push the button that iTunes changes its playback way.
If I press the button it properly changes iTunes palyback settings.

You know what? I’ll make a screencast and I’ll up it onto youtube.

Hi,

Just a quick reply to your post and thanks for posting our codes. I will (for sure, others in this forum will too) take a crack at checking your codes to see where the problem might be.

The use of “to” is just the same as “on” and I am just used to using “my” in my coding to indicate that the handler belongs to the application like “quit me”, “tell me to quit” instead of just coding “quit”. It doesn’t harm to type a little bit more.

In my year or two of AppleScript Studio, I have never used the Debug feature. For some reason, I find it hard to comprehend. I wish someone would write a Help document to help me to comprehend it. What I usually do, if I want to check my variables at some point in the program, is to insert a “display dialog” command. If I don’t get what I want, then I know what the problem is and possibly where the problem code could be. You may want to apply a little bit of this rather “crude” debugging somewhere in your code to see what’s happening.

OK, ShowGetter, I will get back to you when I find something suspicious. Meanwhile, good luck. There is no need to apologize for your English. I understood what you meant completely. It’s just my careless reading sometimes.

archseed:)

Hi ShowGetter,

On a very quick scan of your “setGUI” handler, I notice what I think is an unusual code below:

“set contents of button “shuffle” of window “main” to shuffle_set”

Try to change it to:

 set title of button "shuffle" of window "main" to shuffle_set

You just want to change the title of your button to the current state of iTunes’ shuffle which you already obtained in another code, right?

Hope it works.

archseed :slight_smile:

Hi ShowGetter,

I thought I should quickly confirm my test. In a previous post, I suggested to change the “set contents of button…” to “set title of button…”.

I just tested it and yes, I am happy to tell you, that it should solve your GUI problem. When I tested your unusual “set contents of button…” code, the simple program I created did not give any error. It compiled alright but the button title does not change when the program launches as you have already observed in your case. When I changed my test code to “set title of button…”, then the button title changed properly.

So, that should solve your “bug” issue. Well, at least for now, until you find another bug. This is the life of programmers for sure. Nobody’s perfect the first time.

archseed :slight_smile:

Hi ShowGetter,

Are you up?

I tried to create a simple window prototype with a button to see if I could change the title of the button according to the player state of iTunes. For a while, I thought you had it right, that there was a bug but actually there wasn’t. Here is the code that works. This is in the “awake from nib” handler but I am sure you could put the code somewhere else like “on launch”.


on awake from nib theObject
	using terms from application "iTunes"
		tell application "iTunes"
			activate
			set iTunesStatus to the player state
			if iTunesStatus is not playing then set buttonTitle to "Play"
			if iTunesStatus is playing then set buttonTitle to "Stop"
		end tell
	end using terms from
	set title of button "myButton" of window "main" to buttonTitle
end awake from nib

There is one thing that you must do when calling iTunes and its properties in your codes: use the [using terms from application “iTunes”/end using terms] block. If you don’t use it, then you get some esoteric constants and the button title shows some crazy numbers in it.

These are what I got when I checked the status of iTunes without using the “using terms from” block:

Hi ShowGetter,

Are you up?

I tried to create a simple window prototype with a button to see if I could change the title of the button according to the player state of iTunes. For a while, I thought you had it right, that there was a bug but actually there wasn’t. Here is the code that works. This is in the “awake from nib” handler but I am sure you could put the code somewhere else like “on launch”.


on awake from nib theObject
	using terms from application "iTunes"
		tell application "iTunes"
			activate
			set iTunesStatus to the player state
			if iTunesStatus is not playing then set buttonTitle to "Play"
			if iTunesStatus is playing then set buttonTitle to "Stop"
		end tell
	end using terms from
	set title of button "myButton" of window "main" to buttonTitle
end awake from nib

There is one thing that you must do when calling iTunes and its properties in your codes: use the [using terms from application “iTunes”/end using terms] block. If you don’t use it, then you get some esoteric constants and the button title shows some crazy numbers in it.

These are what I got when I checked the status of iTunes without using the “using terms from” block:

Hi ShowGetter,

Are you up?

I tried to create a simple window prototype with a button to see if I could change the title of the button according to the player state of iTunes. For a while, I thought you had it right, that there was a bug but actually there wasn’t. Here is the code that works. This is in the “awake from nib” handler but I am sure you could put the code somewhere else like “on launch”.


on awake from nib theObject
	using terms from application "iTunes"
		tell application "iTunes"
			activate
			set iTunesStatus to the player state
			if iTunesStatus is not playing then set buttonTitle to "Play"
			if iTunesStatus is playing then set buttonTitle to "Stop"
		end tell
	end using terms from
	set title of button "myButton" of window "main" to buttonTitle
end awake from nib

There is one thing that you must do when calling iTunes and its properties in your codes: use the [using terms from application “iTunes”/end using terms] block. If you don’t use it, then you get some esoteric constants and the button title shows some crazy numbers in it.

These are what I got when I checked the status of iTunes without using the “using terms from” block:

Good luck.

archseed :slight_smile:

ShowGetter,

Sorry to screw up on posting my reply.
As you will notice, it got posted several times. Please ignore the repeated posts. They are one and the same. Something went wrong during posting.

Good luck.

archseed :rolleyes:

Sorry for having let you wait so long. I had a lot to do last time.

Now I got everything running just as I want it to.
There’s just the thing, that I need to use “using terms from”,
but I’m working on it right now and I will get it work ;).

The “Compiler Bug” seems to be really a Xcode bug or lets say issue.
If I compile the App, Xcode automatically launches the App-bundle
before the real compile process (I don’t know why it does that,
but who really cares :rolleyes: ). And Xcode realizes that the
app is already open and opens it a another time as a second process
subordinated to Xcode. That causes the App to be unable to receive
or send commands to other Apps properly.
That’s the reason why it didn’t work properly.
I noticed that the Debug mode launches the App otherwise so
the App worked properly there. It’s a little confusing that it also
did’t work properly when double-cliked in the Finder, but now it works
and that’s whats important :).

I want to thank you very much for your help and support.
You helped me a lot :slight_smile: Thank you!

cheers

ShowGetter

Hi,

Great to know that your app is working.

BTW, there’s nothing wrong with your English this time around. Perfect! :smiley:

archseed :slight_smile:

Nice to hear that :slight_smile: