I am using a script that will allow me to change an illustrator asset link location from my high res asset library to low res asset library or thumb drive and back. I would like to change the script to change the thumb drive to a Box Sync folder. I am able to get the link path to switch from my HR or LR library to Box Sync, but not back from Box Syn to HR or LR.
I am running Mac OS 10.11.4 with Illustrator CC 2015 18.0.0.
Here is my two scripts. First is my thumb drive that works and then my Box Sync that works only one way.
setUSBLinkto "HD TD00"
setLoResLinkto "CG Master_LR"
setHiResLinkto "CG Master_HR"
setNewExt1to ".tif"
setNewExt1Smallto "-sm.tif"
setErrorListto {}
setLinkInspectto {}
tellapplication "Adobe Illustrator"
activate
setuser interaction leveltointeract with all
display dialog "Please chose link mode" buttons {"HiRes", "LoRes", "ThumbDrive"} default button 2
ifthebutton returnedoftheresultis "HiRes" then
setErrorListtoErrorList& myLinkSwitch(document 1, LoResLink, HiResLink, 3, NewExt1)
setErrorListtoErrorList& myLinkSwitch(document 1, USBLink, HiResLink, 3, NewExt1)
elseifbutton returnedoftheresultis "LoRes" then
setErrorListtoErrorList& myLinkSwitch(document 1, HiResLink, LoResLink& ":Assets", 2, NewExt1Small)
setErrorListtoErrorList& myLinkSwitch(document 1, USBLink, LoResLink, 2, NewExt1Small)
else
setErrorListtoErrorList& myLinkSwitch(document 1, LoResLink, USBLink, 2, NewExt1Small)
setErrorListtoErrorList& myLinkSwitch(document 1, HiResLink, USBLink& ":Assets", 2, NewExt1Small)
endif
setuser interaction leveltointeract with all
setErrorListtomyremoveDuplicates(ErrorList)
ifErrorListisnot {} then
setLinkInspectto (choose from listErrorListwith prompt "Reveal The Files" withmultiple selections allowed)
endif
--display dialog "The following files were not relinked:" & return & ErrorList
ifLinkInspectisnot {} then
try
repeatwithalbiefrom 1 tocountofLinkInspect
tellapplication "Finder"
activate
delay 0.5
revealitemalbieofLinkInspect
endtell
endrepeat
endtry
endif
endtell
ongetBaseName2(fName, Char)
tellapplication "System Events"
setNoExtto {}
setZto 0
setBaseNametoreverseofeveryitemoffName
repeatwithidxfrom 1 tocountofBaseName
ifitemidxofBaseNameisCharthen
exitrepeat
else
setZtoZ + 1
endif
endrepeat
returnitems 1 thru ((countofBaseName) - 1 - Z) ofreverseofBaseNameasstring
endtell
endgetBaseName2
onFolderPathtoList(myPath, TrimFront, TrimBack)
setFolderPathto {}
setoldDelimiterstoAppleScript'stext item delimiters-- always preserve original delimiters
setAppleScript'stext item delimitersto {":"}
setpathItemstotext itemsof (myPathastext)
setTFto (TrimFrontasnumber) + 1
setTBto ((countofpathItems) - TrimBackasinteger) asinteger
setAppleScript'stext item delimiterstooldDelimiters
returnitemsTFthruTBofpathItemsaslist
endFolderPathtoList
ontrim_line(this_text, trim_chars, trim_indicator)
-- 0 = beginning, 1 = end, 2 = both
setxtothelengthofthetrim_chars
-- TRIM BEGINNING
ifthetrim_indicatorisin {0, 2} then
repeatwhilethis_textbegins withthetrim_chars
try
setthis_texttocharacters (x + 1) thru -1 ofthis_textasstring
onerror
-- the text contains nothing but the trim characters
return ""
endtry
endrepeat
endif
-- TRIM ENDING
ifthetrim_indicatorisin {1, 2} then
repeatwhilethis_textends withthetrim_chars
try
setthis_texttocharacters 1 thru -(x + 1) ofthis_textasstring
onerror
-- the text contains nothing but the trim characters
return ""
endtry
endrepeat
endif
returnthis_text
endtrim_line
onremoveDuplicates(lst)
locallst, itemRef, res, itm
try
iflst'sclassisnotlistthenerror "not a list." number -1704
scriptk
propertyl : lst
propertyres : {}
endscript
repeatwithitemRefink'sl
setitmtoitemRef'scontents
-- note: minor speed optimisation when removing duplicates
-- from ordered lists: assemble new list in reverse so
-- 'contains' operator checks most recent item first
ifk'sresdoes notcontain {itm} then¬
setk'sres'sbeginningtoitm
endrepeat
returnk'sres'sreverse
onerroreMsgnumbereNum
error "Can't removeDuplicates: " & eMsgnumbereNum
endtry
endremoveDuplicates
onotherTrim(StringToTrim, TheDelimiter, TheDirection)
setTheResultto {}
setStringToTrimtoStringToTrimasstring
ifTheDirectionis 0 then
setZtoreverseofeverycharacterofStringToTrimasstring
repeatwithfrfrom 1 tocountofZ
ifitemfrofZisTheDelimiterthen
exitrepeat
else
setendofTheResulttoitemfrofZ
endif
endrepeat
setTheResulttoreverseofTheResultasstring
else
--Forward Goes Here
endif
endotherTrim
onCharacterCheck(TheString, CheckCharacter)
setCheckSumto 0
setTheStringtoeverycharacterofTheString
repeatwithfrfrom 1 tocountofTheString
ifitemfrofTheStringisCheckCharacterthen
setCheckSumtoCheckSum + 1
endif
endrepeat
returnCheckSum
endCharacterCheck
onLinkSwitch(TheDoc, DriveOld, DrivNew, TheTrim, FileEnd)
tellapplication "Adobe Illustrator"
setuser interaction leveltonever interact
tellTheDoc
setDocLinkstoeveryplaced item
settempErrorto {}
repeatwithAvafrom 1 tocountofDocLinks
setnewlinkto {}
setpathcounttocountofmyFolderPathtoList(file pathofitemAvaofDocLinks, 0, 0)
setNewNametomyFolderPathtoList(file pathofitemAvaofDocLinks, pathcount - 1, 0) asstring
setNewNametomygetBaseName2(NewName, ".")
setNewNametomygetBaseName2(NewName, "-")
setPathCheckto (myFolderPathtoList(file pathofitemAvaofDocLinks, 0, 1))
ifitem 1 ofPathCheckisDriveOldthen
setendofnewlinktoDrivNew& ":"
repeatwithEnzofromTheTrimtocountofPathCheck
setendofnewlinktoitemEnzoofPathCheck
setendofnewlinkto ":"
endrepeat
setnewlinktonewlink& NewName& FileEndasstring
try
setfile pathofitemAvaofDocLinkstonewlink
try
setnameofitemAvaofDocLinkstoNewName& NewExt1asstring
endtry
onerror
setendoftempErrortofile pathofitemAvaofDocLinksasstring
endtry
else
setxtocountofmyFolderPathtoList(file pathofitemAvaofDocLinksasstring, 0, 0)
--return my FolderPathtoList(file path of item Ava of DocLinks & return as string, x - 2, 1)
ifmyFolderPathtoList(file pathofitemAvaofDocLinksasstring, x - 2, 1) asstringisnot "ALT" then
setendoftempErrortofile pathofitemAvaofDocLinksasstring
endif
endif
endrepeat
returntempError
endtell
setuser interaction leveltointeract with all
endtell
endLinkSwitch
Box Sync Script:
setBoxSyncto "Mac OSX:Users:artist:Box%20Sync:CG%20Master_LR"
setLoResLinkto "CG Master_LR"
setHiResLinkto "CG Master_HR"
setNewExt1to ".tif"
setNewExt1Smallto "-sm.tif"
setErrorListto {}
setLinkInspectto {}
tellapplication "Adobe Illustrator"
activate
setuser interaction leveltointeract with all
display dialog "Please chose link mode" buttons {"HiRes", "LoRes", "BoxSync"} default button 2
ifthebutton returnedoftheresultis "HiRes" then
setErrorListtoErrorList& myLinkSwitch(document 1, LoResLink, HiResLink, 3, NewExt1)
setErrorListtoErrorList& myLinkSwitch(document 1, BoxSync, HiResLink, 3, NewExt1)
elseifbutton returnedoftheresultis "LoRes" then
setErrorListtoErrorList& myLinkSwitch(document 1, HiResLink, LoResLink& ":Assets", 2, NewExt1Small)
setErrorListtoErrorList& myLinkSwitch(document 1, BoxSync, LoResLink, 2, NewExt1Small)
elseifbutton returnedoftheresultis "BoxSync" then
setErrorListtoErrorList& myLinkSwitch(document 1, LoResLink, BoxSync, 2, NewExt1Small)
setErrorListtoErrorList& myLinkSwitch(document 1, HiResLink, BoxSync& ":Assets", 2, NewExt1Small)
endif
setuser interaction leveltointeract with all
setErrorListtomyremoveDuplicates(ErrorList)
ifErrorListisnot {} then
setLinkInspectto (choose from listErrorListwith prompt "Reveal The Files" withmultiple selections allowed)
endif
--display dialog "The following files were not relinked:" & return & ErrorList
ifLinkInspectisnot {} then
try
repeatwithalbiefrom 1 tocountofLinkInspect
tellapplication "Finder"
activate
delay 0.5
revealitemalbieofLinkInspect
endtell
endrepeat
endtry
endif
endtell
ongetBaseName2(fName, Char)
tellapplication "System Events"
setNoExtto {}
setZto 0
setBaseNametoreverseofeveryitemoffName
repeatwithidxfrom 1 tocountofBaseName
ifitemidxofBaseNameisCharthen
exitrepeat
else
setZtoZ + 1
endif
endrepeat
returnitems 1 thru ((countofBaseName) - 1 - Z) ofreverseofBaseNameasstring
endtell
endgetBaseName2
onFolderPathtoList(myPath, TrimFront, TrimBack)
setFolderPathto {}
setoldDelimiterstoAppleScript'stext item delimiters-- always preserve original delimiters
setAppleScript'stext item delimitersto {":"}
setpathItemstotext itemsof (myPathastext)
setTFto (TrimFrontasnumber) + 1
setTBto ((countofpathItems) - TrimBackasinteger) asinteger
setAppleScript'stext item delimiterstooldDelimiters
returnitemsTFthruTBofpathItemsaslist
endFolderPathtoList
ontrim_line(this_text, trim_chars, trim_indicator)
-- 0 = beginning, 1 = end, 2 = both
setxtothelengthofthetrim_chars
-- TRIM BEGINNING
ifthetrim_indicatorisin {0, 2} then
repeatwhilethis_textbegins withthetrim_chars
try
setthis_texttocharacters (x + 1) thru -1 ofthis_textasstring
onerror
-- the text contains nothing but the trim characters
return ""
endtry
endrepeat
endif
-- TRIM ENDING
ifthetrim_indicatorisin {1, 2} then
repeatwhilethis_textends withthetrim_chars
try
setthis_texttocharacters 1 thru -(x + 1) ofthis_textasstring
onerror
-- the text contains nothing but the trim characters
return ""
endtry
endrepeat
endif
returnthis_text
endtrim_line
onremoveDuplicates(lst)
locallst, itemRef, res, itm
try
iflst'sclassisnotlistthenerror "not a list." number -1704
scriptk
propertyl : lst
propertyres : {}
endscript
repeatwithitemRefink'sl
setitmtoitemRef'scontents
-- note: minor speed optimisation when removing duplicates
-- from ordered lists: assemble new list in reverse so
-- 'contains' operator checks most recent item first
ifk'sresdoes notcontain {itm} then¬
setk'sres'sbeginningtoitm
endrepeat
returnk'sres'sreverse
onerroreMsgnumbereNum
error "Can't removeDuplicates: " & eMsgnumbereNum
endtry
endremoveDuplicates
onotherTrim(StringToTrim, TheDelimiter, TheDirection)
setTheResultto {}
setStringToTrimtoStringToTrimasstring
ifTheDirectionis 0 then
setZtoreverseofeverycharacterofStringToTrimasstring
repeatwithfrfrom 1 tocountofZ
ifitemfrofZisTheDelimiterthen
exitrepeat
else
setendofTheResulttoitemfrofZ
endif
endrepeat
setTheResulttoreverseofTheResultasstring
else
--Forward Goes Here
endif
endotherTrim
onCharacterCheck(TheString, CheckCharacter)
setCheckSumto 0
setTheStringtoeverycharacterofTheString
repeatwithfrfrom 1 tocountofTheString
ifitemfrofTheStringisCheckCharacterthen
setCheckSumtoCheckSum + 1
endif
endrepeat
returnCheckSum
endCharacterCheck
onLinkSwitch(TheDoc, DriveOld, DrivNew, TheTrim, FileEnd)
tellapplication "Adobe Illustrator"
setuser interaction leveltonever interact
tellTheDoc
setDocLinkstoeveryplaced item
settempErrorto {}
repeatwithAvafrom 1 tocountofDocLinks
setnewlinkto {}
setpathcounttocountofmyFolderPathtoList(file pathofitemAvaofDocLinks, 0, 0)
setNewNametomyFolderPathtoList(file pathofitemAvaofDocLinks, pathcount - 1, 0) asstring
setNewNametomygetBaseName2(NewName, ".")
setNewNametomygetBaseName2(NewName, "-")
setPathCheckto (myFolderPathtoList(file pathofitemAvaofDocLinks, 0, 1))
ifitem 1 ofPathCheckisDriveOldthen
setendofnewlinktoDrivNew& ":"
repeatwithEnzofromTheTrimtocountofPathCheck
setendofnewlinktoitemEnzoofPathCheck
setendofnewlinkto ":"
endrepeat
setnewlinktonewlink& NewName& FileEndasstring
try
setfile pathofitemAvaofDocLinkstonewlink
try
setnameofitemAvaofDocLinkstoNewName& NewExt1asstring
endtry
onerror
setendoftempErrortofile pathofitemAvaofDocLinksasstring
endtry
else
setxtocountofmyFolderPathtoList(file pathofitemAvaofDocLinksasstring, 0, 0)
--return my FolderPathtoList(file path of item Ava of DocLinks & return as string, x - 2, 1)
ifmyFolderPathtoList(file pathofitemAvaofDocLinksasstring, x - 2, 1) asstringisnot "ALT" then
setendoftempErrortofile pathofitemAvaofDocLinksasstring
endif
endif
endrepeat
returntempError
endtell
setuser interaction leveltointeract with all
endtell
endLinkSwitch