[b]I have a script below where if I strip the folder action portion of the script off of it the script works and if I have the folder action code in place the script does not work… Another set of eyes to look at these scripts would be most welcome.
This is the striped code with the only change being the reference to the file.[/b]
tell application “Finder”
activate
set defaultProject to “Miscellaneous”
set defaultContext to “Unassigned”
set theText to read file “:Users:RoonToon:Desktop:Request_E_mail order _ IDEAS.txt”
–set theText to read file this_file
set {od, my text item delimiters} to {my text item delimiters, “EndOfRequest”} – set the text marker
set requestText to text item 1 of theText – get everything up to the marker
set my text item delimiters to od – clean up
set reqLines to paragraphs of requestText – get the lines of text
set reqLines to items 1 through 5 of reqLines & items 7 through end of reqLines – strip line 6
set Requestor to item 7 of reqLines --requestor
set Subject to item 8 of reqLines --subject
set dateofrequest to item 9 of reqLines --date of request
set room to item 10 of reqLines --room number
–set room to last word of roomTemp
set requestItem to item 11 of reqLines --item
set bpi to item 13 of reqLines --BPI
set ProblemDescription to item 16 of reqLines --Problem description
set Requestor to Requestor & " >Miscellaneous @Unassigned#1d#2d "
set newline2 to {Subject, (ASCII character 10), dateofrequest, (ASCII character 10), room, (ASCII character 10), requestItem, (ASCII character 10), bpi, (ASCII character 10), ProblemDescription}
set newline2 to newline2 as text – convert the list back to text
set theText to Requestor
tell application “OmniFocus”
set MyDoc to default document
tell application “OmniFocus” to tell MyDoc
set MyDoc to parse tasks with transport text theText
return theText
set note of first item of MyDoc to newline2
end tell
end tell
end tell
And this is the script with the folder action code in place. Thanks for any help.
on adding folder items to my_folder after receiving the_files
repeat with i from 1 to number of items in the_files
tell application “OmniFocus”
launch
try
set this_file to (item i of the_files)
tell application “Finder”
activate
set defaultProject to “Miscellaneous”
set defaultContext to “Unassigned”
–set theText to read file “:Users:RoonToon:Desktop:Request_E_mail order _ IDEAS.txt”
set theText to read file this_file
set {od, my text item delimiters} to {my text item delimiters, “EndOfRequest”} – set the text marker
set requestText to text item 1 of theText – get everything up to the marker
set my text item delimiters to od – clean up
set reqLines to paragraphs of requestText – get the lines of text
set reqLines to items 1 through 5 of reqLines & items 7 through end of reqLines – strip line 6
set Requestor to item 7 of reqLines --requestor
set Subject to item 8 of reqLines --subject
set dateofrequest to item 9 of reqLines --date of request
set room to item 10 of reqLines --room number
–set room to last word of roomTemp
set requestItem to item 11 of reqLines --item
set bpi to item 13 of reqLines --BPI
set ProblemDescription to item 16 of reqLines --Problem description
set Requestor to Requestor & " >Miscellaneous @Unassigned#1d#2d "
set newline2 to {Subject, (ASCII character 10), dateofrequest, (ASCII character 10), room, (ASCII character 10), requestItem, (ASCII character 10), bpi, (ASCII character 10), ProblemDescription}
set newline2 to newline2 as text – convert the list back to text
set theText to Requestor
tell application “OmniFocus”
set MyDoc to default document
tell application “OmniFocus” to tell MyDoc
set MyDoc to parse tasks with transport text theText
return theText
set note of first item of MyDoc to newline2
end tell
end tell
end tell
add this_file
end try
end tell
end repeat
end adding folder items to
.is no valid path. HFS paths start always with a disk name.
A leading colon is never a replacement for the leading slash in POSIX paths
Or use a relative path
set theText to read file ((path to desktop as text) & "Request_E_mail order _ IDEAS.txt")
When that part of the script is in place it works. Top script works the bottom does not and that is the one I need to work. Need the top script as a folder action. Thanks for the look see.
tell application "OmniFocus"
set MyDoc to default document
tell application "OmniFocus" to tell MyDoc
set MyDoc to parse tasks with transport text theText
return theText
set note of first item of MyDoc to newline2
end tell
end tell
end tell
add this_file
there are double and triple references of Omnifocus and the add line (and the consecutive repeat iterations) will never be executed because of the return statement.
In the script the Finder is not needed at all, and you should avoid nested application tell blocks.
This_file is an alias so omit the keyword file.
I don’t have OmniFocus therefore the script doesn’t compile on my machine
on adding folder items to my_folder after receiving the_files
tell application "OmniFocus" to launch
repeat with i from 1 to number of items in the_files
try
set this_file to (item i of the_files)
set defaultProject to "Miscellaneous"
set defaultContext to "Unassigned"
--set theText to read file ":Users:RoonToon:Desktop:Request_E_mail order _ IDEAS.txt"
set theText to read this_file
set {od, my text item delimiters} to {my text item delimiters, "EndOfRequest"} -- set the text marker
set requestText to text item 1 of theText -- get everything up to the marker
set my text item delimiters to od -- clean up
set reqLines to paragraphs of requestText -- get the lines of text
set reqLines to items 1 through 5 of reqLines & items 7 through end of reqLines -- strip line 6
set Requestor to item 7 of reqLines --requestor
set Subject to item 8 of reqLines --subject
set dateofrequest to item 9 of reqLines --date of request
set room to item 10 of reqLines --room number
--set room to last word of roomTemp
set requestItem to item 11 of reqLines --item
set bpi to item 13 of reqLines --BPI
set ProblemDescription to item 16 of reqLines --Problem description
set Requestor to Requestor & " >Miscellaneous @Unassigned #1d #2d "
set newline2 to {Subject, (ASCII character 10), dateofrequest, (ASCII character 10), room, (ASCII character 10), requestItem, (ASCII character 10), bpi, (ASCII character 10), ProblemDescription}
set newline2 to newline2 as text -- convert the list back to text
set theText to Requestor
tell application "OmniFocus"
set MyDoc to default document
set MyDoc to parse tasks with transport text theText
-- return theText ??
set note of first item of MyDoc to newline2
add this_file
end tell
end try
end repeat
end adding folder items to
Sorry as I am just learning applescript. The code did compile but did not execute. Note the items in blue below as i don’t think that the text file is being read correctly and being assigned to theText variable. Thanks again.
set this_file to (item i of the_files)<—Is the problem here?
set theText to read this_file <------Set the text here
d
on adding folder items to my_folder after receiving the_files
tell application "OmniFocus" to launch
repeat with i from 1 to number of items in the_files
try
set this_file to (item i of the_files)
set defaultProject to "Miscellaneous"
set defaultContext to "Unassigned"
--set theText to read file ":Users:RoonToon:Desktop:Request_E_mail order _ IDEAS.txt"
set theText to read this_file
set {od, my text item delimiters} to {my text item delimiters, "EndOfRequest"} -- set the text marker
set requestText to text item 1 of theText -- get everything up to the marker
set my text item delimiters to od -- clean up
set reqLines to paragraphs of requestText -- get the lines of text
set reqLines to items 1 through 5 of reqLines & items 7 through end of reqLines -- strip line 6
set Requestor to item 7 of reqLines --requestor
set Subject to item 8 of reqLines --subject
set dateofrequest to item 9 of reqLines --date of request
set room to item 10 of reqLines --room number
--set room to last word of roomTemp
set requestItem to item 11 of reqLines --item
set bpi to item 13 of reqLines --BPI
set ProblemDescription to item 16 of reqLines --Problem description
set Requestor to Requestor & " >Miscellaneous @Unassigned #1d #2d "
set newline2 to {Subject, (ASCII character 10), dateofrequest, (ASCII character 10), room, (ASCII character 10), requestItem, (ASCII character 10), bpi, (ASCII character 10), ProblemDescription}
set newline2 to newline2 as text -- convert the list back to text
set theText to Requestor
tell application "OmniFocus"
set MyDoc to default document
set MyDoc to parse tasks with transport text theText
-- return theText ??
set note of first item of MyDoc to newline2
add this_file
end tell
end try
end repeat
end adding folder items to
They are. And no matter how badly this is coded the code below does work in omniscript. Let’t get back to the original question of why it does not work when the folder action scrip code is added.
d
on adding folder items to my_folder after receiving the_files
repeat with i from 1 to number of items in the_files <------- cycles through all files dropped on the folder
tell application “OmniFocus” <— launches OmniFocus
launch
try
set this_file to (item i of the_files) <—sets file name
(everything between these two sets of code works)
add this_file
end try
end tell
end repeat
end adding folder items to
This does work as a standalone script.
tell application “Finder”
activate
set defaultProject to “Miscellaneous”
set defaultContext to “Unassigned”
set theText to read file “:Users:RoonToon:Desktop:Request_E_mail order _ IDEAS.txt”
–set theText to read file this_file
set {od, my text item delimiters} to {my text item delimiters, “EndOfRequest”} – set the text marker
set requestText to text item 1 of theText – get everything up to the marker
set my text item delimiters to od – clean up
set reqLines to paragraphs of requestText – get the lines of text
set reqLines to items 1 through 5 of reqLines & items 7 through end of reqLines – strip line 6
set Requestor to item 7 of reqLines --requestor
set Subject to item 8 of reqLines --subject
set dateofrequest to item 9 of reqLines --date of request
set room to item 10 of reqLines --room number
–set room to last word of roomTemp
set requestItem to item 11 of reqLines --item
set bpi to item 13 of reqLines --BPI
set ProblemDescription to item 16 of reqLines --Problem description
set Requestor to Requestor & " >Miscellaneous @Unassigned#1d#2d "
set newline2 to {Subject, (ASCII character 10), dateofrequest, (ASCII character 10), room, (ASCII character 10), requestItem, (ASCII character 10), bpi, (ASCII character 10), ProblemDescription}
set newline2 to newline2 as text – convert the list back to text
set theText to Requestor
tell application “OmniFocus”
set MyDoc to default document
tell application “OmniFocus” to tell MyDoc
set MyDoc to parse tasks with transport text theText
return theText
set note of first item of MyDoc to newline2
end tell
end tell
end tell