Welcome to the MacNN Forums.

If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

You are here: MacNN Forums > Software - Troubleshooting and Discussion > Developer Center > Bug in AppleScript?

Bug in AppleScript?
Thread Tools
Grizzled Veteran
Join Date: Sep 2000
Location: Springfield, MA
Status: Offline
Reply With Quote
Jun 24, 2002, 04:22 PM
 
I just found a an inconsistency between the results of a script run in "Script Editor" and a script run with osascript.

Here is a simple test case:
</font><blockquote><font size="1" face="Geneva, Verdana, Arial, sans-serif">code:</font><hr /><pre style="font-size:x-small; font-family: monospace;">tell application &quot;iTunes&quot;
set curclass to class of current track as string
end tell

return curclass</pre><hr /></blockquote><font size="1" face="Geneva, Verdana, Arial, sans-serif">When I run this code in Script Editor, "audio CD track" is displayed in the script results window, as it should. However, when I run the code from the terminal, I get the following:
</font><blockquote><font size="1" face="Geneva, Verdana, Arial, sans-serif">code:</font><hr /><pre style="font-size:x-small; font-family: monospace;">[pete@ligeia pete]$ osascript test.as
?lass cCDT?
[pete@ligeia pete]$ </pre><hr /></blockquote><font size="1" face="Geneva, Verdana, Arial, sans-serif">I already made an (ugly) workaround for this bug, but I'd like to see if anyone can reproduce, or explain this problem. I have the new AS update, but I have not tested this with the previous version.
We hope your rules and wisdom choke you / Now we are one in everlasting peace
-- Radiohead, Exit Music (for a film)
     
Mactoid  (op)
Grizzled Veteran
Join Date: Sep 2000
Location: Springfield, MA
Status: Offline
Reply With Quote
Jun 24, 2002, 04:37 PM
 
One more thing, I have only seen this problem with casting the current track class type in iTunes to a string. For comparison, note that the following test case:
</font><blockquote><font size="1" face="Geneva, Verdana, Arial, sans-serif">code:</font><hr /><pre style="font-size:x-small; font-family: monospace;">tell application &quot;iTunes&quot;
set curname to name of current track as string
end tell

return curname</pre><hr /></blockquote><font size="1" face="Geneva, Verdana, Arial, sans-serif">Works fine in both the Script Editor and the osascript command.
We hope your rules and wisdom choke you / Now we are one in everlasting peace
-- Radiohead, Exit Music (for a film)
     
Mac Elite
Join Date: Oct 2000
Status: Offline
Reply With Quote
Jun 24, 2002, 08:20 PM
 
</font><blockquote><font size="1" face="Geneva, Verdana, Arial, sans-serif">quote:</font><hr /><font size="1" face="Geneva, Verdana, Arial, sans-serif">Originally posted by Mactoid:
<strong>One more thing, I have only seen this problem with casting the current track class type in iTunes to a string. For comparison, note that the following test case:
</font><blockquote><font size="1" face="Geneva, Verdana, Arial, sans-serif">code:</font><hr /><pre style="font-size:x-small; font-family: monospace;">tell application &quot;iTunes&quot;
set curname to name of current track as string
end tell

return curname</pre><hr /></blockquote><font size="1" face="Geneva, Verdana, Arial, sans-serif">Works fine in both the Script Editor and the osascript command.</strong></font><hr /></blockquote><font size="1" face="Geneva, Verdana, Arial, sans-serif">Does osascript have its own AppleScript interpreter?

It seems that it's interpreting it as this:

tell application "iTunes"
  set curclass to class of (current track as string)
end tell

But it cannot coerce a track to a string. Now what I assume you're trying to do is coerce the class of current track to a string. Which you could do by doing:

tell application "iTunes"
  set curclass to (class of current track) as string
end tell

Where first you get current track's class, and then coerce that into a string as the result is simple enough to coerce.

Also the return seems a little useless no? Here's what I would use personally:

tell application "iTunes" to copy current track's class as string to curclass

If that fails...

tell application "iTunes" to copy (current track's class) as string to curclass

But it shouldn't fail <img border="0" title="" alt="[Wink]" src="wink.gif" />
     
Mactoid  (op)
Grizzled Veteran
Join Date: Sep 2000
Location: Springfield, MA
Status: Offline
Reply With Quote
Jun 24, 2002, 09:54 PM
 
Yeah, that return was useless. Does AS automatically returns the last value assigned or something?

Anyway, thanks for the ideas, however all of the versions that you posted still resulted in the same problem from the osascript command <img border="0" title="" alt="[Frown]" src="frown.gif" />
We hope your rules and wisdom choke you / Now we are one in everlasting peace
-- Radiohead, Exit Music (for a film)
     
   
Thread Tools
Forum Links
Forum Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On
Top
Privacy Policy
All times are GMT -5. The time now is 09:38 PM.
All contents of these forums © 1995-2011 MacNN. All rights reserved.
Branding + Design: www.gesamtbild.com
vBulletin v.3.8.7 © 2000-2011, Jelsoft Enterprises Ltd., Content Relevant URLs by vBSEO 3.3.2