(* Prefix the items in the selection with my group name
by korm 20150227
https://discourse.devontechnologies.com/t/variable-for-getting-group-name/18354/1
*)
property theDivider : ": "
tell application id "DNtp"
set theSelection to the selection
set groupPrefix to (the name of the current group) & theDivider
repeat with thisItem in theSelection
if the type of thisItem is not "group" then
if the name of thisItem does not contain groupPrefix then
set the name of thisItem to groupPrefix & (the name of thisItem)
open for access thisItem with write permission
write groupPrefix to thisItem
close access thisItem
end if
end if
end repeat
end tell
I really appreciate that, honestly. I dug a little deeper and came up with this solution:
(* Prefix the items in the selection with my group name
by korm 20150227
https://discourse.devontechnologies.com/t/variable-for-getting-group-name/18354/1
*)
property theDivider : ": "
tell application id "DNtp"
set theSelection to the selection
set groupPrefix to (the name of the current group) & theDivider
repeat with thisItem in theSelection
if the type of thisItem is not "group" then
if the name of thisItem does not contain groupPrefix then
set the name of thisItem to groupPrefix & (the name of thisItem)
if the type of thisItem is in {"rtf", "rtfd", "txt"} then
set foo to (open for access thisItem with write permission)
set theData to (read foo)
write groupPrefix & theData to thisItem
end if
end if
end if
end repeat
end tell
While it’s already checking the file type correctly it doesn’t alter the file’s content at all…
(* Prefix the items in the selection with my group name
by korm 20150227
https://discourse.devontechnologies.com/t/variable-for-getting-group-name/18354/1
*)
property theDivider : ": "
tell application id "DNtp"
set theSelection to the selection
if theSelection is {} then error "Select an item, please"
set groupPrefix to (the name of the current group) & theDivider
repeat with thisItem in theSelection
if the type of thisItem is not "group" then
if the name of thisItem does not contain groupPrefix then
set the name of thisItem to groupPrefix & (the name of thisItem)
if the type of thisItem is in {"rtf", "rtfd", "txt"} then
set oldText to the rich text of thisItem
set the rich text of thisItem to groupPrefix & oldText
end if
end if
end if
end repeat
end tell
…which seemed to be a simpler solution but to no avail.