I have a script that I call from another script. If I don’t call it it runs great but if called I get the following error – Can’t get item 1 of {}.
Being a beginner I am sure I am doing something stupid but I can figure out why it will run if not called and fail if called??
The only thing I do is comment out the on run and end run statement of the called program and uncomment out the set myCitType lines.
thanks for help
Roger
on run {myCitType}
– for testing only
–set myCitType to “BK”
global myCitCount
set myCitCount to ""
global myCitRecords
set myCitRecords to {}
global myCitation
set myCitation to ""
-- Format Citation for outpput
GetLoadCitRecords(myCitType)
-- format citation
set myRepeat to 1
repeat
-- get record to format
set myRec to item myRepeat of myCitRecords -- <<<<<-- this is where the error occurs
-- do function getFormat
GetFormat(myRec)
-- increment myRepeat to get next record
set myRepeat to myRepeat + 1
-- check if Done button pushed
set myDone to item 8 of myRec
if myDone = "Done" then exit repeat
end repeat
--send finished formated citation to clipboard
set the clipboard to myCitation
end run
–***************************************************************************************
– Sub Load Citation Records
–***************************************************************************************
on GetLoadCitRecords(myCitType)
-- define fields
set myCitRecords to {}
set myCitCount to ""
-- Set values for each record
if myCitType = "BK" then
set myRec001 to {"(BK) ", "001", "Page Number ", "Page Number:", ", ", "attribute", "N", "Next"}
set end of myCitRecords to myRec001
set myCitCount to myCitCount + 1
set myRec001 to {"(BK) ", "002", "Person of Interest ", "Person of Interest:", ", ", "attribute", "Y", "Next"}
set end of myCitRecords to myRec001
set myCitCount to myCitCount + 1
set myRec001 to {"(BK) ", "003", "(recorded ", "Date:", ")", "Date", "Y", "Done"}
set end of myCitRecords to myRec001
set myCitCount to myCitCount + 1
end if
return
end GetLoadCitRecords
–***************************************************************************************
– Format Record based on passed variables function
–***************************************************************************************
on GetFormat(myRec)
-- set fields
set myCit to ""
-- set display of mandatory field
if item 7 of myRec = "Y" then
set myMandatory to "**"
else
set myMandatory to ""
end if
-- set up for date defalut
if item 6 of myRec = "Date" then
--Format current date
set myYear to get the (year of (current date)) as string
set myMonth to get the (month of (current date)) as string
set myDay to get the (day of (current date)) as string
set myCit to myDay & " " & myMonth & " " & myYear
end if
-- repeat if option field is "Y" and field is blank
repeat
set tempVar to display dialog item 1 of myRec & myMandatory & "Enter " & item 4 of myRec default answer myCit buttons {"Restart", "Cancel", item 8 of myRec} default button item 8 of myRec
set myCit to text returned of result
if myCit ≠"" then
set myCitation to myCitation & item 3 of myRec & myCit & item 5 of myRec
end if
-- check to see if option field is not "N" or if field has data
if item 7 of myRec = "N" then exit repeat
-- exit repeat if
if myCit ≠"" then exit repeat
end repeat
end GetFormat
This is the calling program
– Set myType to citation type
set myType to “BK”
– Run Citation Formater Script
run script file “Macintosh HD 2:RGS:RGSFormater.scpt” with parameters {myType}
– say finished
say “Finished”