Hey guys, first post here at macscripter, but not a forum newbie. Anyway, what I’m trying to do is make a database using database events that holds a bunch of exercises. I then chose a certain number of random ones to do each day. So I created a database, then added records corresponding to each exercise. Then I wanted to make a list of the daily chosen exercises. The problem is, my “records” don’t keep their “name.” and when I try to reference the “name”, I just get “false” as a result. Here are the scripts I’ve written.
Create database script: (Works fine)
set theOutputFolder to choose folder with prompt "Please select an output folder:"
set theNameofDatabase to text returned of (display dialog "What would you like the name to be?" default answer "" buttons {"OK", "Cancel"} default button "OK")
tell application "Database Events"
make new database with properties {name:theNameofDatabase, location:theOutputFolder}
save database 1
end tell
Add records with exercise names: (I know it adds records, cause the record COUNT goes up, but I don’t know if the “names” work.)
set theDBPath to POSIX path of "Macintosh HD:Users:kylereeping:Documents:Databases:Core Exercises.dbev"
tell application "Database Events"
launch
open database theDBPath
end tell
tell application "Finder"
set namee to display dialog "Please enter a core exercise." default answer "" buttons ["OK", "Cancel"] default button "OK"
end tell
tell application "Database Events"
tell database "Core Exercises"
make new record with properties {name:namee}
end tell
save database "Core Exercises"
end tell
Choose Random Exercises/Records: (Works, but returns false, false, false etc. instead of names)
set theDBPath to POSIX path of "Macintosh HD:Users:kylereeping:Documents:Databases:Core Exercises.dbev"
tell application "Database Events"
launch
open database theDBPath
tell database 1
set RecCount to (count records)
end tell
end tell
set RndList to {}
set ListCount to 0
repeat until ListCount = 6
set RndNum to (random number from 1 to RecCount)
if RndNum is not in RndList then
set RndList to RndList & RndNum
set ListCount to ListCount + 1
end if
end repeat
set ExerList to {"A", "B", "C", "D", "E", "F"}
set i to 1
tell application "Database Events"
tell database 1
repeat 6 times
set item i of ExerList to name of record (item i in RndList)
set i to i + 1
end repeat
end tell
end tell
return ExerList
What am I doing wrong??? Thanks in advance.