I’ve never found a straightforward method. Instead, for a script that I use to add extended attributes to old WordPerfect files, I used the hex string of the text of the attribute that I found in other files that already had the correct attribute.
Here is the routine I use, which is far more elaborate than you need, because it first tests the file to determine which version of WordPerfect created the file so that it can apply the correct attribute, but you’ll get the idea. The only line you really need is the one that runs a shell script with xattr. It’s possible that all you need is the string that begins com.agileTortoise, etc, and not any hex string.
The code is incompetent because I don’t know how to write anything better, unfortunately, but it seems to work.
on setAttr(wpf, wpfPath, folderProcess)
try
set hasHeader to ((read wpf for 4 as data) is «data rdatFF575043»)
if hasHeader is true then
set fixDocument to false
set fileTypeByte to (read wpf from 10 for 1 as data)
set versionByte to (read wpf from 11 for 1 as data)
--if not fileTypeByte is «data rdat16» then -- not WP Graphic
if (fileTypeByte is «data rdat2C») then -- WPMac
set fixDocument to true
if (versionByte is «data rdat02») then -- Mac WP 2.1
set hexString to "5750443257504332000000000000000000000000000000007400000000000000"
else if (versionByte is «data rdat03») then -- Mac WP 3.x
set hexString to "5750443357504332000000000000000000000000000000007400000000000000"
else if (versionByte is «data rdat04») then -- Mac WP 3.5e
set hexString to "5750443457504332000000000000000000000000000000006E74000000000000"
else -- use WP5 for anything else
set hexString to "2E57503557504332010000000000000000000000000000000000000000000000"
end if
else if (fileTypeByte is «data rdat0A») then -- WPDOS
set fixDocument to true
if (versionByte is «data rdat00») or (versionByte is «data rdat02») or (versionByte is «data rdat03») or (versionByte is «data rdat04») or (versionByte is «data rdat0A») or (versionByte is «data rdat2C») then
if (versionByte is «data rdat00») then -- WP5.x
set hexString to "2E57503557504332010000000000000000000000000000000000000000000000"
else -- WPDOS 6+ and miscellaneous others
set hexString to "2E57503657504332000000000000000000000000000000000000000000000000"
end if
end if
end if
if fixDocument is true then
try
do shell script "xattr -w -x com.apple.FinderInfo" & space & hexString & space & quoted form of wpfPath
-- set end of fixedList to wpfPath
set end of fixedList to "a"
tell application "System Events"
try
set fileKind to kind of wpf
if fileKind does not contain "Word Perfect fics" then
if fileKind does not contain "WordPerfect" then
if name of wpf is not in noProcessList then
set noMsgShow to my badFileMsg(wpf, wpfPath, folderProcess, noMsgShow)
end if
end if
end if
end try
end tell
on error err
if err does not contain "hexString" then
activate
display dialog err
end if
end try
end if
--end if
end if
end try
end setAttr
Very interesting! I could use this in a couple of my scripts generating PDFs which I prefer to open in Preview instead of Acrobat, the default on my system (Monterey 12.6.3).
Your code is working well here but returns a quarantine error at the second attempt to open the file.
I managed this issue by deleting the quarantine attribute:
set aPath to "some path"
set theAttr to "62706C6973743030D30102030405065776657273696F6E54706174685F101062756E646C656964656E74696669657210005F10202F53797374656D2F4170706C69636174696F6E732F507265766965772E6170705F1011636F6D2E6170706C652E50726576696577080F171C2F31540000000000000101000000000000000700000000000000000000000000000068"
do shell script "xattr -w -x com.apple.LaunchServices.OpenWith " & quoted form of theAttr & space & quoted form of aPath
do shell script "xattr -w -x 'com.apple.quarantine' nil " & quoted form of aPath
But a problem remains: the Finder information window for the file will not reflect the change until you restart of the system or the Finder.
Can anyone give us a solution to update this information?