when i try to get the size of a song and set it in a text field i get this error:
The bug is located in this handler:
on UpdateInfo()
tell application "iTunes"
set myCount to 1
set MyiTunesTracks to {} -- alle tracks (itunes notatie) naar list
repeat count myPlaylist times
set end of MyiTunesTracks to (every track whose name is (item 1 of item myCount of myPlaylist) as string and artist is (item 2 of item myCount of myPlaylist) as string)
set myCount to myCount + 1
end repeat
set myBytes to 0
set myCount to 1 -- totaal aantal bytes verkrijgen
repeat count MyiTunesTracks times
set V to size of (item myCount of MyiTunesTracks)
set myBytes to myBytes + V
set myCount to myCount + 1
end repeat
set myMB to myBytes / 1024 as integer
set myGB to myBytes / 1024 / 1024 as integer
set myTotalSeconds to 0
set myCount to 1 -- totaal aantal seconden verkrijgen
repeat count MyiTunesTracks times
set MMSS to time of (item myCount of MyiTunesTracks)
set CM to word 1 of MMSS
set CS to word 2 of MMSS
set TS to CM * 60 + CS
set myTotalSeconds to myTotalSeconds + TS
end repeat
set myUpdateTracks to count MyiTunesTracks as string -- aantal gekozen tracks
end tell
-- Text field veranderen
SecondsToString(myTotalSeconds) -- seconden naar time string (myTimeString)
set contents of text field "AAantal" of window "add" to myUpdateTracks
set contents of text field "ATijd" of window "add" to myTimeString as string
set contents of text field "AGrootte" of window "add" to (myGB as string) & " GB"
end UpdateInfo
and this is the entire applescript file of my Xcode Project if you should think the bug’s location is somewhere else:
[i]
-- Song Chooser.applescript
-- Song Chooser
-- Created by ief2 on 13/09/09.
-- Copyright 2009 __MyCompanyName__. All rights reserved.
global myArtists
global myPlaylist
global myGtracks
global myGArtists
global myArtist
global MyiTunesTracks
global myTimeString
global myTotalSeconds
global myUpdateTracks
global myGB
on clicked theObject
(* als SStart *)
if name of theObject is "SStart" then
close window "SStart"
show window "StartProgress"
start progress indicator "SPSpinner" of window "StartProgress" -- start spinner
-- alle artiesten in een lijst
tell application "iTunes" -- maak lege list
set tracksCount to (count every track of playlist 2)
set myArtists to {}
end tell
set myCount to 1
repeat tracksCount times
set contents of text field "SPProgress" of window "StartProgress" to ¬
"Bezig met track " & myCount & "/" & tracksCount -- update text field
-- artist van track myCOunt toevoegen
tell application "iTunes"
tell playlist 2 to tell track myCount
set tracksArtist to artist
if tracksArtist is not in myArtists then set end of myArtists to tracksArtist
end tell
set myCount to myCount + 1
end tell
end repeat
-- sluit startprogress window, open add window, stop spinner
stop progress indicator "SPSpinner" of window "StartProgress"
close window "StartProgress"
show window "Add"
-- Artiesten view updaten van window "add"
set contents of table view "AArtiesten" of scroll view "AArtiesten" of window "Add" to myArtists
UpdateInfo()
end if
(* als AKiesArtiest *)
if name of theObject is "AKiesArtiest" then
set myArtist to contents of data cell 1 of selected data row of table view "AArtiesten" of scroll view "AArtiesten" of window "Add" -- gekozen artiest verkrijgen
-- tracks verkrijgen
start (progress indicator "ASpinner" of window "Add") -- start spinner
tell application "iTunes"
set GekozenTracks to reverse of (get name of every track whose artist is myArtist) -- alle liedjes van artiest verktijgen
end tell
-- tabel updaten, spinner stoppen
set contents of table view "ATracks" of scroll view "ATracks" of window "Add" to GekozenTracks
stop progress indicator "ASpinner" of window "Add"
UpdateInfo()
end if
(* als AVerwijderArtiest *)
if name of theObject is "AVerwijderArtiest" then
set myDArtist to selected data rows of table view "AArtiesten" of scroll view "AArtiesten" of window "add"
delete item 1 of myDArtist
UpdateInfo()
end if
(* als AVoegToe *)
if name of theObject is "AVoegToe" then
-- alles verkrijgen, lijst bijwerken
set myGTrack to contents of data cell 1 of selected data row of table view "ATracks" of scroll view "ATracks" of window "Add" as string -- verkrijg artiest naam
set myGArtist to myArtist as string -- verkrijg artiest
set V to {myGTrack, myGArtist} as list
set myCount to 1
set A to "Start"
repeat count myPlaylist times
if item myCount of myPlaylist is V then set A to "Stop" -- myPlaylist bijwerken checken
set myCount to myCount + 1
end repeat
if A is not "Stop" then set end of myPlaylist to V -- myPlaylist bijwerken
-- artiesten en tracks tabel bijwerken
set contents of table view "AGekozen" of scroll view "AGekozen" of window "add" to myPlaylist
UpdateInfo()
end if
(* als AVerwijderTrakcs *)
if name of theObject is "AVerwijderTrakcs" then
set myDelete to contents of selected data row of table view "AGekozen" of scroll view "AGekozen" of window "Add" as list -- geselecteerde row verkrijgen
set myNewPlaylist to {}
set myCount to 1 -- nieuwe playlist maken
repeat count myPlaylist times
if item myCount of myPlaylist is not myDelete then
set end of myNewPlaylist to item myCount of myPlaylist
end if
set myCount to myCount + 1
end repeat
set myPlaylist to myNewPlaylist -- myPlaylist updaten
set contents of table view "AGekozen" of scroll view "AGekozen" of window "Add" to myPlaylist -- tabel updaten
UpdateInfo()
end if
(* als AAfspeellijst *)
if name of theObject is "AAfspeellijst" then
set V to (current date) as string
set AppleScript's text item delimiters to {"-"}
get words 2 thru -1 of V as string
set myDateString to result
tell application "iTunes"
make new playlist with properties {name:"Song Chooser " & myDateString} -- nieuwe afspeellijst maken
set myCount to 1
set MyiTunesTracks to {} -- alle tracks (itunes notatie) naar playlist
repeat count myPlaylist times
set end of MyiTunesTracks to every track whose name is (item 1 of item myCount of myPlaylist as string) and artist is (item 2 of item myCount of myPlaylist as string)
set myCount to myCount + 1
end repeat
set myCount to 1
repeat count myPlaylist times
duplicate item 1 of item myCount of MyiTunesTracks to playlist ("Song Chooser " & myDateString)
set myCount to myCount + 1
end repeat
end tell
UpdateInfo()
end if
end clicked
on awake from nib theObject
set myPlaylist to {} as list
set myGtracks to {} as list
set myGArtists to {} as list
if name of theObject is "Add" then
UpdateInfo()
end if
end awake from nib
(* ===== MY HANDLERS ===== *)
on UpdateInfo()
tell application "iTunes"
set myCount to 1
set MyiTunesTracks to {} -- alle tracks (itunes notatie) naar list
repeat count myPlaylist times
set end of MyiTunesTracks to (every track whose name is (item 1 of item myCount of myPlaylist) as string and artist is (item 2 of item myCount of myPlaylist) as string)
set myCount to myCount + 1
end repeat
set myBytes to 0
set myCount to 1 -- totaal aantal bytes verkrijgen
repeat count MyiTunesTracks times
set V to size of (item myCount of MyiTunesTracks)
set myBytes to myBytes + V
set myCount to myCount + 1
end repeat
set myMB to myBytes / 1024 as integer
set myGB to myBytes / 1024 / 1024 as integer
set myTotalSeconds to 0
set myCount to 1 -- totaal aantal seconden verkrijgen
repeat count MyiTunesTracks times
set MMSS to time of (item myCount of MyiTunesTracks)
set CM to word 1 of MMSS
set CS to word 2 of MMSS
set TS to CM * 60 + CS
set myTotalSeconds to myTotalSeconds + TS
end repeat
set myUpdateTracks to count MyiTunesTracks as string -- aantal gekozen tracks
end tell
-- Text field veranderen
SecondsToString(myTotalSeconds) -- seconden naar time string (myTimeString)
set contents of text field "AAantal" of window "add" to myUpdateTracks
set contents of text field "ATijd" of window "add" to myTimeString as string
set contents of text field "AGrootte" of window "add" to (myGB as string) & " GB"
end UpdateInfo
on SecondsToString(mySeconds)
set H to mySeconds div 60 div 60
set M to (mySeconds - H * 60 * 60) div 60
set S to mySeconds - H * 60 * 60 - M * 60
set myTimeString to (H & "h " & M & "m " & S & "s") as string
end SecondsToString
[/i]
Thanx,
ief2
ps is there a spoiler-code for hiding some parts of your post, because i think this post is a little bit to big