Yvan if I was that clever, to rig the video, I did not need help with this script. :-)) Indeed, it is unedited footage, only shrunk to a smaller size to be able to send it in an email. Scouts honour.
Can’t get file “Seva Server:Users:ganesh:Desktop:3_20200525_101434_800.jpg” of application “Image Events”.
The log said:
tell application “Script Editor”
choose file of type {“public.jpeg”} with multiple selections allowed
→ {alias “Seva Server:Users:ganesh:Desktop:3.jpg”}
end tell
tell application “Image Events”
launch
end tell
tell current application
info for alias “Seva Server:Users:ganesh:Desktop:3.jpg”
→ {name:“3.jpg”, creation date:date “Monday, 25 May 2020 at 09:15:20”, modification date:date “Monday, 25 May 2020 at 09:15:20”, size:2218263, folder:false, alias:false, package folder:false, visible:true, extension hidden:false, name extension:“jpg”, displayed name:“3.jpg”, default application:alias “Seva Server:System:Applications:Preview.app:”, kind:“JPEG image”, file type:“file creator:“type identifier:“public.jpeg”, locked:false, busy status:false, short version:””, long version:“”}
end tell
tell application “Image Events”
open file “Seva Server:Users:ganesh:Desktop:3.jpg”
→ image “3.jpg”
end tell
tell current application
info for alias “Seva Server:Users:ganesh:Desktop:3.jpg”
→ {name:“3.jpg”, creation date:date “Monday, 25 May 2020 at 09:15:20”, modification date:date “Monday, 25 May 2020 at 09:15:20”, size:2218263, folder:false, alias:false, package folder:false, visible:true, extension hidden:false, name extension:“jpg”, displayed name:“3.jpg”, default application:alias “Seva Server:System:Applications:Preview.app:”, kind:“JPEG image”, file type:“file creator:“type identifier:“public.jpeg”, locked:false, busy status:false, short version:””, long version:“”}
current date
→ date “Monday, 25 May 2020 at 10:15:18”
end tell
tell application “Image Events”
get dimensions of image “3.jpg”
→ {}
get resolution of image “3.jpg”
→ {}
scale image “3.jpg” to size 800
save image “3.jpg” in “Seva Server:Users:ganesh:Desktop:3_20200525_101518_800.jpg” with icon
→ missing value
close image “3.jpg”
open file “Seva Server:Users:ganesh:Desktop:3_20200525_101518_800.jpg”
→ error number -1728 from file “Seva Server:Users:ganesh:Desktop:3_20200525_101518_800.jpg”
Result:
error “Image Events got an error: Can’t get file "Seva Server:Users:ganesh:Desktop:3_20200525_101518_800.jpg".” number -1728 from file “Seva Server:Users:ganesh:Desktop:3_20200525_101518_800.jpg”
PS I am testing presently on a different 10.15 machine.
Sorry, what you report does not match what other users get under 10.15 with the same script.
As I am not a diviner it is not possible for me to guess what exotic adjustment was made on your machine.
This is the first time this has happened but I have to give up.
Yvan KOENIG running High Sierra 10.13.6 in French (VALLAURIS, France) lundi 25 mai 2020 11:33:38
Yvan, I know you have no crystal ball. I am using a Mac mini 2020 to test on this morning, that has a fresh 10.15 install (2 weeks ago) and the latest update to 10.15.4.
There are non what so ever exotic adjustments on it. Zero. There are no applications running on it that are not Mac Native and of those only a few. It is my blind server and mainly used for backup storage and sending out automatic mails via the native app Mail.
I switched to the MM as I have been testing so far on an external HD running 10.15.4 on my MBP. I thought this might influence stuff negatively.
Could the error be in the fact that I run an Englisch OS version and you a French?
The script doesn’t rely upon localized features.
What I know is that Catalina requires some specific settings to be able do achieve some tasks.
As I can’t install this system, I am unable to list those settings. I just know that they mainly are supposed to give some permissions to the scripts.
Back to the applet which you sent me.
I really don’t understand how you were able to create such a mess.
Your package contain three copies of the script.
It’s normal for a droplet created with Script Debugger.
What is odd is that these versions don’t match.
What appears when we ask Script Editor to open the script is the content of the embedded file named “main.rtf” but, what is executed in the content of the embedded file named “main.scpt” (which is identical to what is in the embedded file named “main.recover.rtf”).
Please, open your applet in Script Editor
select all
create a new empty script
paste in it
save as “4Yvan.app”
then drag and drop a jpeg upon it.
With this clean app you will see that what I wrote is the normal behavior.
As I can’t explain what you did to build the foolish applet I think that the only thing to do is to trash it and quickly empty the trash.
If somebody may describe the settings required by Catalina, maybe you will solve your problem.
I apologize but for me, GAME OVER.
Yvan KOENIG running High Sierra 10.13.6 in French (VALLAURIS, France) lundi 25 mai 2020 13:46:21
So Yvan sent me a copy of the script. The explanation is that the script you saved is not commented out, but the version that Script Editor auto-saved was made after the script was commented out. So when you opened the script again you saw the last auto-saved version, but the document was still dirty (a black dot in the red button in the title bar). However, that version isn’t the version that runs when you double-click.I suspect that somehow something has got damaged along the line after that.
The moral of the story: always save, never rely on auto-save.
on open draggedItems
repeat with currentFile in draggedItems
-- change targetBytes value to max file size in bytes
(my resizedJpegFromPath:(POSIX path of currentFile) maxHeightOrWidth:800 targetBytes:100000)
end repeat
end open
Change that 100000 to however many bytes is your limit.
Yes, I know this and here I am complete sure all is well. All my other scripts run flawlessly and all permissions in ‘Privacy’ tab are given.
Neither do I but I think Shane expained how it possibly could have happened.
I did that, and hate to say it does not work.
I think my settings are correct in the system. However should anybody have a tip as to what to check I love to hear.
I sincerely apologise if I upset you. I might not be the best AS scripter (I know I am not) but at no time did I intently try to upset the system. I am enormously grateful for the help you and others gave and have given me in the past solving AS challenges. Once again very sorry for the mess.
on open draggedItems
repeat with currentFile in draggedItems
-- change targetBytes value to max file size in bytes
(my resizedJpegFromPath:(POSIX path of currentFile) maxHeightOrWidth:800 targetBytes:100000)
end repeat
end open
use scripting additions
use framework "Foundation"
use framework "AppKit"
on resizedJpegFromPath:imagePath maxHeightOrWidth:maxDim targetBytes:maxBytes
set imagePath to current application's NSString's stringWithString:imagePath
set outPath to (imagePath's stringByDeletingPathExtension()'s stringByAppendingString:"-out")
set outPath to outPath's stringByAppendingPathExtension:"jpg"
-- Get the contents of the passed picture
set theImageRep to current application's NSBitmapImageRep's imageRepWithContentsOfFile:imagePath -- load the file
set theClip to current application's NSPasteboard's generalPasteboard()
-- Extract its original size
set oldHeight to theImageRep's pixelsHigh()
set oldWidth to theImageRep's pixelsWide()
if oldWidth > oldHeight then
set theWidth to maxDim
set theHeight to oldHeight * maxDim / oldWidth
else
set theHeight to maxDim
set theWidth to oldWidth * maxDim / oldHeight
end if
set newRep to (current application's NSBitmapImageRep's alloc()'s initWithBitmapDataPlanes:(missing value) pixelsWide:theWidth pixelsHigh:theHeight bitsPerSample:8 samplesPerPixel:4 hasAlpha:yes isPlanar:false colorSpaceName:(current application's NSDeviceRGBColorSpace) bytesPerRow:0 bitsPerPixel:32)
-- store the existing graphics context
current application's NSGraphicsContext's saveGraphicsState()
-- set graphics context to new context based on the new bitmapImageRep
current application's NSGraphicsContext's setCurrentContext:(current application's NSGraphicsContext's graphicsContextWithBitmapImageRep:newRep)
theImageRep's drawInRect:{origin:{x:0, y:0}, |size|:{width:theWidth, height:theHeight}} fromRect:(current application's NSZeroRect) operation:(current application's NSCompositeSourceOver) fraction:1.0 respectFlipped:false hints:(missing value)
-- restore state
current application's NSGraphicsContext's restoreGraphicsState()
set compFactor to 0.8 -- starting compression value
set compMax to 0.2 -- compression limit
repeat
set theData to newRep's representationUsingType:(current application's NSJPEGFileType) |properties|:{NSImageCompressionFactor:compFactor}
if compFactor > compMax and theData's |length|() > maxBytes then
-- too big, so try with more compression
set compFactor to compFactor * 0.9
else -- give up
exit repeat
end if
end repeat
theData's writeToFile:outPath atomically:true
end resizedJpegFromPath:maxHeightOrWidth:targetBytes:
set anImage to choose file of type {"public.png", "public.tiff", "public.jpeg"}
my resizedJpegFromPath:(POSIX path of anImage) maxHeightOrWidth:800 targetBytes:100000
in your post you said to chance the 100000 to change the output size of the file.
Is this in this line (top)?
(my resizedJpegFromPath:(POSIX path of currentFile) maxHeightOrWidth:800 targetBytes:100000)
Or this line (bottom)?
my resizedJpegFromPath:(POSIX path of anImage) maxHeightOrWidth:800 targetBytes:100000
Or both?
I ask as any changes made in each of these lines or in both at the same time, make no difference. The output is always a 48KB file. For example I tried 1000000000 and 100 no difference.
Or did I not understand you correctly?
PS
I make a new AS doc and paste the whole text in every time. Next save is as an application. No save as or duplicate.
I hate to write that it’s the kind of sentence which really doesn’t help.
Are you writing about the applet with every instructions disabled ?
If it’s that, what’s the meaning of your statement ?
I will deliberately shout. YOU WERE WARNED SEVERAL TIMES THAT WHEN IT’S SAVED CORRECTLY, SUCH SCRIPT DOES ABSOLUTELY NOTHING.
Yvan KOENIG running High Sierra 10.13.6 in French (VALLAURIS, France) lundi 25 mai 2020 16:04:54
It sounds like you’ve modified the document, but not saved it. Also, extreme values are a bad test; it will give up before it gets anywhere near 100, and it will start off under 100000000 anyway.
Must I understand that, at last, you were able to get the scripts vents to do what they are supposed to achieve or that you just got the script using ASObjC doing the job ?
Yvan KOENIG running High Sierra 10.13.6 in French (VALLAURIS, France) mardi 26 mai 2020 15:17:31
Yvan not sure what you are asking here. And not sure about it using ASObjC, I Googled it and I do not think we are using this here. I surely never installed it.
hopefully this answers your question, what I did is I used the script Shane wrote and combined that without any changes - post number 66 and 56. That shrinks the images I drop on it in 10.15.4.
It is a tick different in the end result compared to my old script results, but one can live with that.