tell application id "DNtp"
try
set this_selection to the selection
if this_selection is {} then error "Please select some images."
repeat with this_item in this_selection
if the type of this_item is equal to picture then
try
set this_image to the image of this_item
with timeout of 30 seconds
tell application "Image Events"
launch
set this_file to open file this_image
scale this_file by factor 0.5
save this_file without icon
close this_file
end tell
end timeout
end try
end if
end repeat
on error error_message number error_number
if the error_number is not -128 then display alert "DEVONthink" message error_message as warning
end try
end tell
That is not the correct form for smart rule scripts. You must be using the on performSmartRule() handler. This is added automatically in the smart rule action so you had to have deleted it. See the Automation chapter of the built-in Help and manual.
PS: Why are you tagging documents as resizedbefore they’ve been resized?
Another question, why is it when the action is “when opening” every time I open that item it resize it? Same thing with “after synchronization” any update to the file it resizes it.
it thats normal behaviour, then the action should be labeled “On open very time”
on performSmartRule(theRecords)
tell application id "DNtp"
repeat with theRecord in theRecords
if (type of theRecord is picture) then -- Shouldn't be necessary if smart rule criteria is set up correctly. However, it's not bad to error trap your code.
set recPath to (path of theRecord as string)
tell application "Image Events"
set theImage to open recPath
set {w, h} to dimensions of theImage -- Using a variable here is to satisfy an issue with Image Events.
scale theImage to size ((w / 2) as integer) -- Halving one dimension works as the scaling retains the aspect ratio of the original
save theImage
end tell
end if
set tags of theRecord to (tags of theRecord & "resized")
end repeat
end tell
end performSmartRule