I wrote a Watched Folder script which, among other things, will remove the DTP app. extension (.qxp, .indd, etc.) from the postscript file before transferring the .ps file to Distiller Watched Folder.
The script works if I run it natively but when I add code for the Watched Folder, “on adding folder items to ff after receiving L” and “end adding folder items to” I get the Syntax Error: Expected “end” but found “on” at line: on set_item_name(this_item, new_item_name).
I assume it’s because the word “on” is being confused as a Watched Folder Action.
Do you have any ideas for a wordaround? Any help would be greatly appreciated.
on adding folder items to ff after receiving L
--Check to ensure Distiller is running.
tell application "System Events"
set myList to (name of every process)
end tell
if (myList contains "Distiller") is false then
display dialog "Acrobat Distiller has not been launched.
Please launch Distiller, right-click on its dock icon and select Open at Login.
If the PostScript-PDF workflow process does not begin, remove the current PostScript file and regenerate a new PostScript file or remove the current PostScript file and log out and log back in." buttons {"OK"} default button 1
return
end if
--Check to ensure folder.joboptions are in Watched Folders.
tell application "Finder"
set posixPath1 to ("/Users/Shared/Work/00_PDF_HI_RES/")
set fileURL1 to posixPath1 as POSIX file
set theAlias1 to fileURL1 as alias
tell application "Finder" to set finderRef1 to item theAlias1
set theFolder1 to theAlias1
try
if file "folder.joboptions" of theFolder1 exists then
else
display dialog "The file, folder.joboptions, cannot be found in the 00_PDF_HI_RES folder of the Work folder. Please take note of this message and contact your system administrator immediately." buttons {"OK"} default button 1
return
end if
end try
end tell
tell application "Finder"
set posixPath2 to ("/Users/Shared/Work/00_PDF_LO_RES/")
set fileURL2 to posixPath2 as POSIX file
set theAlias2 to fileURL2 as alias
tell application "Finder" to set finderRef2 to item theAlias2
set theFolder2 to theAlias2
try
if file "folder.joboptions" of theFolder2 exists then
else
display dialog "The file, folder.joboptions, cannot be found in the 00_PDF_LO_RES folder of the Work folder. Please take note of this message and contact your system administrator immediately." buttons {"OK"} default button 1
return
end if
end try
end tell
--Find PS files in ¢ Postscripts folder and duplicate to HiRes-Trash folder.
tell application "Finder"
set posixPath3 to ("/Users/Shared/Work/¢ Postscripts/")
set fileURL3 to posixPath3 as POSIX file
set theAlias3 to fileURL3 as alias
tell application "Finder" to set finderRef3 to item theAlias3
set psFolder to theAlias3
set posixPath4 to ("/Users/Shared/Work/¢ Postscripts/HiRes-Trash/")
set fileURL4 to posixPath4 as POSIX file
set theAlias4 to fileURL4 as alias
tell application "Finder" to set finderRef4 to item theAlias4
set HiResTrash to theAlias4
try
if ((items of psFolder) whose name ends with (".ps")) exists then
duplicate ((items of psFolder) whose name ends with (".ps")) to HiResTrash with replacing
end if
end try
end tell
--Delete DTP file extensions for LoRes.
tell application "Finder"
set posixPath5 to ("/Users/Shared/Work/¢ Postscripts/")
set fileURL5 to posixPath5 as POSIX file
set theAlias5 to fileURL5 as alias
tell application "Finder" to set finderRef5 to item theAlias5
set psFolder to theAlias5
try
if ((items of psFolder) whose name ends with (".ps")) exists then
set source_folder to psFolder as alias
set the search_parameter to name of ((items of psFolder) whose name ends with (".ps"))
set search_string to {".qxp"}
set replacement_string to {""}
set item_list to list folder psFolder without invisibles
set source_folder to psFolder as string
repeat with i from 1 to number of items in item_list
set this_item to item i of item_list
set this_item to (source_folder & this_item) as alias
set this_info to info for this_item
set current_name to name of this_info
set change_flag to false
if current_name contains search_string then
set the change_flag to true
if change_flag is true then
set AppleScript's text item delimiters to search_string
set text_item_list to every text item of current_name
set AppleScript's text item delimiters to replacement_string
set new_item_name to text_item_list as string
set AppleScript's text item delimiters to ""
my set_item_name(this_item, new_item_name)
end if
end if
end repeat
end if
end try
end tell
on set_item_name(this_item, new_item_name)
tell application "Finder"
set parent_container_path to (the container of this_item) as text
if not (exists item (the parent_container_path & new_item_name)) then
try
set the name of this_item to new_item_name
my set_item_name(this_item, new_item_name)
end try
end if
end tell
end set_item_name
tell application "Finder"
set posixPath6 to ("/Users/Shared/Work/¢ Postscripts/")
set fileURL6 to posixPath6 as POSIX file
set theAlias6 to fileURL6 as alias
tell application "Finder" to set finderRef6 to item theAlias6
set psFolder to theAlias6
try
if ((items of psFolder) whose name ends with (".ps")) exists then
set source_folder to psFolder as alias
set the search_parameter to name of ((items of psFolder) whose name ends with (".ps"))
set search_string to {".indd"}
set replacement_string to {""}
set item_list to list folder psFolder without invisibles
set source_folder to psFolder as string
repeat with i from 1 to number of items in item_list
set this_item to item i of item_list
set this_item to (source_folder & this_item) as alias
set this_info to info for this_item
set current_name to name of this_info
set change_flag to false
if current_name contains search_string then
set the change_flag to true
if change_flag is true then
set AppleScript's text item delimiters to search_string
set text_item_list to every text item of current_name
set AppleScript's text item delimiters to replacement_string
set new_item_name to text_item_list as string
set AppleScript's text item delimiters to ""
my set_item_name1(this_item, new_item_name)
end if
end if
end repeat
end if
end try
end tell
on set_item_name1(this_item, new_item_name)
tell application "Finder"
set parent_container_path to (the container of this_item) as text
if not (exists item (the parent_container_path & new_item_name)) then
try
set the name of this_item to new_item_name
my set_item_name1(this_item, new_item_name)
end try
end if
end tell
end set_item_name1
--Delete DTP file extensions and add "HR" suffix for HiRes.
tell application "Finder"
set posixPath7 to ("/Users/Shared/Work/¢ Postscripts/HiRes-Trash/")
set fileURL7 to posixPath7 as POSIX file
set theAlias7 to fileURL7 as alias
tell application "Finder" to set finderRef7 to item theAlias7
set HiResTrash to theAlias7
try
if ((items of HiResTrash) whose name ends with (".ps")) exists then
set source_folder to HiResTrash as alias
set the search_parameter to name of ((items of HiResTrash) whose name ends with (".ps"))
set search_string to {".qxp"}
set replacement_string to {"HR"}
set item_list to list folder HiResTrash without invisibles
set source_folder to HiResTrash as string
repeat with i from 1 to number of items in item_list
set this_item to item i of item_list
set this_item to (source_folder & this_item) as alias
set this_info to info for this_item
set current_name to name of this_info
set change_flag to false
if current_name contains search_string then
set the change_flag to true
if change_flag is true then
set AppleScript's text item delimiters to search_string
set text_item_list to every text item of current_name
set AppleScript's text item delimiters to replacement_string
set new_item_name to text_item_list as string
set AppleScript's text item delimiters to ""
my set_item_name2(this_item, new_item_name)
end if
end if
end repeat
end if
end try
end tell
on set_item_name2(this_item, new_item_name)
tell application "Finder"
set parent_container_path to (the container of this_item) as text
if not (exists item (the parent_container_path & new_item_name)) then
try
set the name of this_item to new_item_name
my set_item_name2(this_item, new_item_name)
end try
end if
end tell
end set_item_name2
tell application "Finder"
set posixPath8 to ("/Users/Shared/Work/¢ Postscripts/HiRes-Trash/")
set fileURL8 to posixPath8 as POSIX file
set theAlias8 to fileURL8 as alias
tell application "Finder" to set finderRef8 to item theAlias8
set HiResTrash to theAlias8
try
if ((items of HiResTrash) whose name ends with (".ps")) exists then
set source_folder to HiResTrash as alias
set the search_parameter to name of ((items of HiResTrash) whose name ends with (".ps"))
set search_string to {".indd"}
set replacement_string to {"HR"}
set item_list to list folder HiResTrash without invisibles
set source_folder to HiResTrash as string
repeat with i from 1 to number of items in item_list
set this_item to item i of item_list
set this_item to (source_folder & this_item) as alias
set this_info to info for this_item
set current_name to name of this_info
set change_flag to false
if current_name contains search_string then
set the change_flag to true
if change_flag is true then
set AppleScript's text item delimiters to search_string
set text_item_list to every text item of current_name
set AppleScript's text item delimiters to replacement_string
set new_item_name to text_item_list as string
set AppleScript's text item delimiters to ""
my set_item_name3(this_item, new_item_name)
end if
end if
end repeat
end if
end try
end tell
on set_item_name3(this_item, new_item_name)
tell application "Finder"
set parent_container_path to (the container of this_item) as text
if not (exists item (the parent_container_path & new_item_name)) then
try
set the name of this_item to new_item_name
my set_item_name3(this_item, new_item_name)
end try
end if
end tell
end set_item_name3
--Move PS files to 00_PDF_LO_RES In.
tell application "Finder"
set posixPath9 to ("/Users/Shared/Work/¢ Postscripts/")
set fileURL9 to posixPath9 as POSIX file
set theAlias9 to fileURL9 as alias
tell application "Finder" to set finderRef9 to item theAlias9
set psFolder to theAlias9
set posixPath10 to ("/Users/Shared/Work/00_PDF_LO_RES/In/")
set fileURL10 to posixPath10 as POSIX file
set theAlias10 to fileURL10 as alias
tell application "Finder" to set finderRef10 to item theAlias10
set LoResIn to theAlias10
try
if ((items of psFolder) whose name ends with (".ps")) exists then
get every item of psFolder whose name ends with (".ps")
move (every item of psFolder whose name ends with (".ps")) to LoResIn with replacing
end if
end try
end tell
--Move PS files to 00_PDF_HI_RES In.
tell application "Finder"
set posixPath11 to ("/Users/Shared/Work/¢ Postscripts/HiRes-Trash/")
set fileURL11 to posixPath11 as POSIX file
set theAlias11 to fileURL11 as alias
tell application "Finder" to set finderRef11 to item theAlias11
set HiResTrash to theAlias11
set posixPath12 to ("/Users/Shared/Work/00_PDF_HI_RES/In/")
set fileURL12 to posixPath12 as POSIX file
set theAlias12 to fileURL12 as alias
tell application "Finder" to set finderRef12 to item theAlias12
set HiResIn to theAlias12
try
if ((items of HiResTrash) whose name ends with (".ps")) exists then
get every item of HiResTrash whose name ends with (".ps")
move (every item of HiResTrash whose name ends with (".ps")) to HiResIn with replacing
end if
end try
end tell
end adding folder items to
Model: Dual 2.7 GHz PPC G5
AppleScript: 1.10.7
Browser: Safari 522.12.1
Operating System: Mac OS X (10.4)