Xcode Yosemite 10.10.1 cocoa-Applescript iTunes Tell blocks not called

I could have sworn earlier in the day tell blocks for iTunes was working. I am not 100% sure because I am also using the “com.apple.iTunes.playerInfo” in the real app.

But below is a Simple cocoa-Applescript written in Xcode Version 6.1 (6A1052c) Yosemite 10.10.1 which is also exhibiting the same behaviour.

The direct tell application “iTunes” to work but the tell block does not. Annoying and odd…

Is anyone else getting this oddness?? anyone know what is going on??

 script AppDelegate
	property parent : class "NSObject"
	
	-- IBOutlets
	property theWindow : missing value
	
	on applicationWillFinishLaunching_(aNotification)
  -- tell application "iTunes" to playPause
     -- tell application "iTunes" to playPause
     
      --##THIS WORKS
      tell application "iTunes" to   set currentTrackName to name of current track as string
      log "iTunes currentTrackName " & currentTrackName


--## THIS TELL BLOCK DOES NOT GET ENTERED ??
        tell application "iTunes"
            log "HERE"
            set currentTrackName to name of current track as string
            
            set trackNumber to track number of current track as string
            set albumArtist to album artist of current track as string
            if albumArtist contains "missing value" or albumArtist is "" then
                set albumArtist to  artist  of current track as string
            end if
            set trackCount to track count of current track as string
            
            log "iTunes albumArtist " & albumArtist
            
        end tell
	end applicationWillFinishLaunching_
	
	on applicationShouldTerminate_(sender)
		-- Insert code here to do any housekeeping before your application quits 
		return current application's NSTerminateNow
	end applicationShouldTerminate_
	
end script

I think you need to move your logging outside of the iTunes tell block. Something like:


--## THIS TELL BLOCK DOES NOT GET ENTERED ??

log "HERE"

tell application "iTunes"
	
	set currentTrackName to name of current track as string
	
	set trackNumber to track number of current track as string
	set albumArtist to album artist of current track as string
	
	if albumArtist contains "missing value" or albumArtist is "" then
		set albumArtist to artist of current track as string
	end if
	
	set trackCount to track count of current track as string
	
end tell

log "iTunes albumArtist " & albumArtist


Hello.

By all means if it is the log statment that breaks the tell block, then the reason for that is that log isn’t part of the application itunes, and therefore won’t work anymore fixing the culprit is easy enough though:

tell application "iTunes"
     tell me to log "something is going on in iTunes tell block"
end tell

Not quite. In an ASObjC-based app like this it needs to be “tell current application to log…”.

Hello.

I am sorry about that Shane, I didn’t notice it was ASOC from the post above. -I shan’t read that sloppily for the future.

Hi All,

Thanks for the replies,

Shane was correct within the Tell block you need to use it with the tell current application….

But oddly the log did not break the code. I actually only put that in after it stopped working,

For some reason things started working again even if I left the old log syntax in the tell block. I did not do any changes to the code at the time of it starting to work so I cannot determine what whats going on??