Along with the information window, a dialog can be put up to get the whereFrom text, with a little AppleScriptObjC (since a shell script has been posted in another answer) to add it. Extending the Automator folder action in my answer to your previous topic, the replacement Run AppleScript action would look something like:
use AppleScript version "2.4" -- Yosemite (10.10) or later
use framework "Foundation"
use scripting additions
property useBinary : missing value
on run {input, parameters}
repeat with anItem in input
tell application "Finder"
activate
open information window of anItem
end tell
set response to (display dialog "Enter text to add to whereFroms:" default answer "" buttons {"Enter", "Skip"} default button 2)
if button returned of response is "Enter" then
addWhereFrom(text returned of response, anItem)
end if
end repeat
return input
end run
to addWhereFrom(newItem, filePath) -- add to existing whereFroms, trimming duplicates
set whereFroms to readWhereFroms(filePath)
set end of whereFroms to (newItem as text)
set whereFroms to (current application's NSOrderedSet's orderedSetWithArray:whereFroms)'s allObjects()
writeWhereFroms(whereFroms, filePath)
end addWhereFrom
to readWhereFroms(filePath) -- get a list of whereFroms from the extended attribute
set filePath to quoted form of POSIX path of filePath
set attribute to missing value
set useBinary to missing value -- keep track of which it is
try -- get existing attribute as property list
set attribute to (do shell script "xattr -p com.apple.metadata:kMDItemWhereFroms " & filePath & " | xxd -r -p | plutil -convert xml1 -o - -") -- convert from binary
set useBinary to true
on error -- oops, not a binary plist, so try XML
try -- skip error if no attribute
set attribute to (do shell script "xattr -p com.apple.metadata:kMDItemWhereFroms " & filePath)
set useBinary to false
end try
end try
if attribute is in {missing value, ""} then return {}
# deserialize the list from the property list string
set theData to (current application's NSString's stringWithString:attribute)'s dataUsingEncoding:(current application's NSUTF8StringEncoding)
return (current application's NSPropertyListSerialization's propertyListWithData:theData options:(current application's NSPropertyListMutableContainersAndLeaves) format:(missing value) |error|:(missing value)) as list
end readWhereFroms
to writeWhereFroms(theList, filePath) -- set the extended attribute to a list of whereFroms
set filePath to quoted form of POSIX path of filePath
# serialize the list into a property list string
set theData to (current application's NSPropertyListSerialization's dataWithPropertyList:theList format:(current application's NSPropertyListXMLFormat_v1_0) options:0 |error|:(missing value))
set plist to (current application's NSString's alloc's initWithData:theData encoding:(current application's NSUTF8StringEncoding)) as text
if useBinary is false then -- set XML plist
do shell script "xattr -w com.apple.metadata:kMDItemWhereFroms " & quoted form of plist & space & filePath
else -- convert and set binary plist
set bplist to do shell script "echo " & quoted form of plist & " | plutil -convert binary1 -o - - | xxd -p"
do shell script "xattr -w -x com.apple.metadata:kMDItemWhereFroms " & bplist & space & filePath
end if
end writeWhereFroms
To use the above script by itself, just remove {input, parameters}
from the run
handler declaration, and replace the input
variable or set it to your own list of file items, for example from a choose file
dialog.