[jawsscripts] Re: JAWS script how you alphabetize items or compare

  • From: "John Martyn" <johnrobertmartyn@xxxxxxxxx>
  • To: <jawsscripts@xxxxxxxxxxxxx>
  • Date: Thu, 29 Mar 2012 18:20:47 -0700

Hi Andrew and Doug,
That string length thing totally fell flat for the purpose it was supposed
to serve. I did one better though and here is the function. Keep in mind
that segment2 has to be returned before segment1 when you call the function
or else it doesn't do anything. Don't ask me why, when I reversed the order
in which I made the function calls it magically worked like micky mouse on
crack.
Basically I examine the string segment and replace all spaces with the
character "a". This is because a space is treated differently than a
character. By doing this with a stringReplaceSubStrings I made it a whole
word. Then I run it through a while statement to make the lengths exactly
the same before the comparison.
It is the most reliable thing and works perfectly. Also below this first
function is me calling the functions and getting not only alphabetized for
the track names, but it reorders the actual track item in the music library.
It also returns you to the last selection . The time it takes for a long
string segment like 150 segments is about 10 seconds. For just viewing
tracks it hardly takes any time at all. I thought of creating a global that
can update in the function because I would only have to call the function
once. It can only return one thing at once, but I left it as is. Take a
look:

function AlphabetizeTheSegments(string segment1, string segment2, int
theSegment)
;sort the segmented strings from highest to lowest
var
variant newList,
variant newList2,
variant exclude,
variant tempList,
string tempMod,
string modMax,
string theMax,
int tempMax,
int skipIt,
int trigger,
int safety,
int trigger2,
int safety2,
int trigger3,
int safety3
let theMax = "zzzzzzz"
while trigger != 1
;iterate through the list for the highest number
while trigger2 != 1
let safety2 = safety2+1

while trigger3 != 1
let safety3 = safety3+1
if StringSegment (exclude, "|", safety3) == safety2 then
let skipIt = 1
let trigger3 = 1
endif
if safety3 >= StringSegmentCount (exclude, "|") then
let trigger3 = 1
endif
endwhile
let trigger3 = 0
let safety3 = 0

if skipIt == 0
let tempList = StringSegment (segment1, "|", safety2)
let tempMod = StringReplaceSubstrings (tempList, " ", "a")
let modMax = StringReplaceSubstrings (theMax, " ", "a")
while trigger3 != 1
let safety3 = safety3+1
if StringLength (tempMod) < StringLength (modMax) then
let tempMod = tempMod+"a"
elif StringLength (tempMod) > StringLength (modMax) then
let modMax = modMax+"a"
elif StringLength (tempMod) == StringLength (modMax) then
let trigger3 = 1
endif
endwhile
let trigger3 = 0
let safety3 = 0
if tempMod < modMax then
let theMax = tempList
let tempMax = safety2
endif

else
let skipIt = 0
endif

if safety2 == StringSegmentCount (segment1, "|") then
let trigger2 = 1
endif
endwhile
let trigger2 = 0
let safety2 = 0


if exclude == "" then
let exclude = tempMax
let newList = StringSegment (segment1, "|", tempMax)
let newList2 = StringSegment (segment2, "|", tempMax)
let theMax = "zzzzzzz"
else
let exclude = exclude+"|"+tempMax
let newList = newList+"|"+StringSegment (segment1, "|", tempMax)
let newList2 = newList2+"|"+StringSegment (segment2, "|", tempMax)
let theMax = "zzzzzzz"
endif


if StringSegmentCount (exclude, "|") == StringSegmentCount (segment1, "|")
then
let trigger = 1
endif
endwhile
let trigger = 0
let trigger2 = 0
let safety = 0
let safety2 = 0
if theSegment == 1 then
return newList
elif theSegment == 2 then
return newList2
endif
EndFunction

Here is where I am calling the functions to get an idea of what is being
manipulated in a menu driven system.

function ViewAllTracks(string theArtist,int addTracks,int deleteTracks)
var
int trigger,
int trigger2,
int safety2,
int trigger3,
int safety3
while trigger != 1
Say("Viewing "+theArtist+" tracks",3)
Say("Please Wait.",3)
;Say("Press escape or Cancel to return to the previous Menu",3)
var
int i,
object o,
object s,
string choices,
variant trackList,
variant trackListCount,
string trackName
let s = iTunesApp.librarysource.playlists.item(theSelectedPlaylist)
let o = iTunesApp.librarysource.playlists.item(2).tracks

while trigger2 != 1
let safety2 = safety2+1
if theArtist == StringSegment (theArtists, "|", safety2) then
if trackList == "" then
let trackList = StringSegment (theTrackNames, "|", safety2)
let trackListCount = safety2
else
let trackList = trackList+"|"+StringSegment (theTrackNames, "|", safety2)
let trackListCount = trackListCount+"|"+safety2
endif
if addTracks == 1 then
s.addtrack(o.item(safety2))
elif deleteTracks == 1 then
o.item(safety2).delete
endif
endif
if safety2 >= StringSegmentCount (theArtists, "|") then
let trigger2 = 1
endif
endwhile
if addTracks == 0 && deleteTracks == 0 then
;must do the track count first, for some strange reason it only works this
way
let trackListCount = AlphabetizeTheSegments(trackList,trackListCount,2)
let trackList = AlphabetizeTheSegments(trackList,trackListCount,1)


let i = DlgSelectItemInList (trackList, "Viewing All Tracks", 0, i)
else
return
endif

if i == 0 then
return
else
ViewTrackOptions(StringSegment (trackList, "|", i), StringSegment
(trackListCount, "|", i))
endif
endwhile
EndFunction






__________�

View the list's information and change your settings at 
//www.freelists.org/list/jawsscripts

Other related posts: