Hi,
I’m stuck with following problem: I’m trying to build a folder action that parses a XML file and makes a alias to that file using an extracted XML value.
It works as a script with a hard coded reference to a specific XML file. So, this works:
-- the XML file
set _theXMLFile to "/Users/kaidoh/Library/Caches/Metadata/com.culturedcode.things/Things/0C0197FC-8ED1-42BE-8BAB-827832576645.thingsitem"
tell application "System Events"
-- this extracts an attribute from the XML file I want to use as name for the alias
tell XML element 1 of XML element 1 of contents of XML file _theXMLFile
set _theTitle to (value of XML attribute "title")
end tell
set _theXMLFile to _theXMLFile as POSIX file
tell application "Finder"
set _theAlias to make new alias file at POSIX file "/Users/kaidoh/Library/Application Support/LaunchBar/ThingsIndex" to _theXMLFile
set the name of _theAlias to _theTitle
end tell
end tell
The problem comes in when I try to turn this code into a folder action. I don’t know, why this fails:
-- analog to the hard coded example above
-- the folder action is meant to be attached to the folder
-- "/Users/kaidoh/Library/Caches/Metadata/com.culturedcode.things/Things"
on adding folder items to _thisFolder after receiving _theseItems
repeat with i from 1 to number of items in _theseItems
set _thisItem to item i of _theseItems
tell application "System Events"
tell XML element 1 of XML element 1 of contents of XML file _thisItem
set _theTitle to (value of XML attribute "title")
end tell
set _theXMLFile to _thisItem as POSIX file
tell application "Finder"
set _theAlias to make new alias file at POSIX file "/Users/kaidoh/Library/Application Support/LaunchBar/ThingsIndex" to _theXMLFile
set the name of _theAlias to _theTitle
end tell
end tell
end repeat
end adding folder items to
My guess is that I would need to hand over _thisItem to the XML file function in a different way - but can’t get my head (and googleing skills) around it.
Any pointers to a solution would be welcome.