Monday, May 25, 2020

#26 2020-05-22 10:55:00 am

ChangeAgent
Member
From:: Scotland
Registered: 2008-03-07
Posts: 292

Re: I have a script to shrink pictures that stopped working under 10.15.

Yvan, thanks, and first off, all the suggested scripts you post make the image bigger. 

My present challenge is that the script works (see both below) in the test version I made.  If I make a new one it does not work.  So, if I copy and paste the script in a new AS window, save it as an App, it gives the errors I posted in the my last post.

So, this one works (yes with the alias and I will change it once the present problem is solved)

Applescript:

use AppleScript version "2.5" -- (10.11) or later
use framework "Foundation"
use scripting additions
----------------------------------------------------------------

tell application "Image Events"
   launch
end tell

on open draggeditems
   repeat with currentFile in draggeditems
       tell application "Image Events"
           set openedFile to open (currentFile as alias)
           
           set fileLocation to the location of openedFile
           set fileName to the name of openedFile
           
           scale openedFile to size 2000
           save openedFile with icon
           close openedFile
       end tell
       
       tell application "Finder"
           set the name of file fileName of fileLocation to ¬
               (fileName)
       end tell
   end repeat
end open

and this one too

Applescript:

use AppleScript version "2.5" -- (10.11) or later
use framework "Foundation"
use scripting additions
----------------------------------------------------------------

set theFile to choose file of type {"public.png", "public.jpeg"}

set theFile to theFile as «class furl»

set POSIXPath to POSIX path of theFile
log POSIXPath -- to check that it's on an external device
tell application "Image Events"
   try
       set openedFile to open theFile -- a «class furl» object
       properties of openedFile
       close openedFile
   end try
   try
       set openedFile2 to open POSIXPath -- a POSIX Path
       properties of openedFile2
       close openedFile2
   end try
end tell

set thisNSURL to current application's NSURL's fileURLWithPath:POSIXPath
set nsMetaItem to current application's NSMetadataItem's alloc()'s initWithURL:thisNSURL
# Build a list of every available metadatas
set theMetadata to nsMetaItem's valuesForAttributes:(nsMetaItem's attributes())
return theMetadata as list

I will now be of-line till tomorrow.

Offline

 

#27 Yesterday 03:43:00 am

Yvan Koenig
Member
Registered: 2006-09-14
Posts: 4344

Re: I have a script to shrink pictures that stopped working under 10.15.

Always under 10.13.6, I made numerous tests and discovered an interesting feature.

I saved 3 versions of this script:

Applescript:

tell application "Image Events"
   launch
end tell
property mode : 3 -- try with the values 1, 2, 3
-- 1 --> alias
-- 2 --> «class furl»
-- 3 --> POSIX Path
on open draggeditems
   repeat with currentFile in draggeditems
       if mode = 1 then
           set thePicture to currentFile as text
       else if mode = 2 then
           set thePicture to currentFile as «class furl» --> «class furl»
       else if mode = 3 then
           set thePicture to POSIX path of currentFile --> text
       end if
       tell application "Image Events"
           if mode = 1 then
               set openedFile to open file thePicture
           else
               set openedFile to open thePicture
           end if
           set fileLocation to the location of openedFile
           set fileName to the name of openedFile
           (*
           scale openedFile to size 800
           save openedFile with icon
           *)

           close openedFile
       end tell
       tell me to say "It worked"
       tell application "Finder"
           set the name of file fileName of fileLocation to (fileName)
       end tell
   end repeat
end open

With a single change : the value of the property named mode.
The three versions work flawlessly.
BUT, here is the discovery, to get such behavior I was forced to save a script built from a blank document.
At first, I created  version #1.app in which mode was set to 1.
I applied cmd + shift + S to create a new copy in which I set mode to 2 and saved as version #2.app
Damned, when I try to drag and drop a picture upon the app's icon, the picture was not treated and its icon was moved on the desktop.
So I deleted version #2.app, opened version #1.app, select all, copy, paste in a new blank window and at last, saved as version #2.app.
Bingo, this time, drag and drop behaved flawlessly.

I didn't really built droplet for years so I don't know if this “surprising” behavior is new but at least it may explain what you got.

Given that, I decided to build new versions which, from my point of view, are cleaner.

Applescript:


property mode : 1 -- try with the values 1, 2, 3
-- 1 --> alias
-- 2 --> «class furl»
-- 3 --> POSIX Path

on open draggeditems
   tell application "Image Events" to launch
   
   repeat with currentFile in draggeditems
       if mode = 1 then
           set thePicture to currentFile as text
       else if mode = 2 then
           set thePicture to currentFile as «class furl» --> «class furl»
       else if mode = 3 then
           set thePicture to POSIX path of currentFile --> text
       end if
       tell application "Image Events"
           if mode = 1 then
               set openedFile to open file thePicture
           else
               set openedFile to open thePicture
           end if
           -- set fileLocation to the location of openedFile
           -- set fileName to the name of openedFile
           
           scale openedFile to size 800
           save openedFile with icon
           
           close openedFile
       end tell

       (*
       tell me to say "It worked"
       tell application "Finder"
           set the name of file fileName of fileLocation to (fileName)
       end tell
       *)

   end repeat
end open

Of course, the “surprising” protocol was required, but the three new versions behaved flawlessly.

Yvan KOENIG running High Sierra 10.13.6 in French (VALLAURIS, France) samedi 23 mai 2020 11:41:20

Offline

 

#28 Yesterday 04:20:45 am

ChangeAgent
Member
From:: Scotland
Registered: 2008-03-07
Posts: 292

Re: I have a script to shrink pictures that stopped working under 10.15.

Yvan I am not at the machine but will be later this PM.  Will test and report back.

and interesting your discovery.  makes me feel less stupid. :-)

Last edited by ChangeAgent (Yesterday 04:21:51 am)

Offline

 

#29 Yesterday 07:16:15 am

peavine
Member
From:: Prescott, Arizona
Registered: 2018-09-04
Posts: 478

Re: I have a script to shrink pictures that stopped working under 10.15.

ChangeAgent wrote:

Yvan, thanks, and first off, all the suggested scripts you post make the image bigger.



I've lost track of this thread, and this may be known,  but the increased file size could be a result of the following line:

Applescript:

save openedFile with icon

Change it as follows to see reduced file sizes:

Applescript:

save openedFile

In my testing with a 270 KB PNG original, the output file contained 410 KB with icon and 87 KB without icon. This is with Yvan's must-work script from post 25.

Last edited by peavine (Yesterday 07:41:23 am)


2018 Mac mini - macOS Catalina

Online

 

#30 Yesterday 07:58:44 am

ChangeAgent
Member
From:: Scotland
Registered: 2008-03-07
Posts: 292

Re: I have a script to shrink pictures that stopped working under 10.15.

Peavine, greetings.

Changing that line makes no difference.  As before, a 1.8 MB jpeg becomes 2.2MB.  A 3.2MB png stays the same size.  All that happens is that the size of the icon picture becomes bigger.

I am really stumped that it works on your end and not on mine.

I am on OS 10.15.4 on a MM 2020.

Offline

 

#31 Yesterday 08:03:43 am

peavine
Member
From:: Prescott, Arizona
Registered: 2018-09-04
Posts: 478

Re: I have a script to shrink pictures that stopped working under 10.15.

ChangeAgent wrote:

Peavine, greetings.

Changing that line makes no difference.  As before, a 1.8 MB jpeg becomes 2.2MB.  A 3.2MB png stays the same size.  All that happens is that the size of the icon picture becomes bigger.

I am really stumped that it works on your end and not on mine.

I am on OS 10.15.4 on a MM 2020.



I don't understand that either. There's some other factor at work that we are missing.

I understand that you want to use Image Events but have your tried my script from post 13. It uses sips and this could be helpful to understand what's happening. On my Catalina computer, this script worked with PNG and JPEG files on boot and external drives.

I see you got a 2020 MM. I have a 2018 MM and love it. smile

Last edited by peavine (Yesterday 08:13:49 am)


2018 Mac mini - macOS Catalina

Online

 

#32 Yesterday 08:05:31 am

ChangeAgent
Member
From:: Scotland
Registered: 2008-03-07
Posts: 292

Re: I have a script to shrink pictures that stopped working under 10.15.

Yvan I am back at the machine.  Tested.  And as before no cigar.  A 1.8 MB jpeg becomes 2.2MB.  A 3.2MB png stays the same size.  All that happens is that the size of the icon picture becomes bigger.

Why would it not work?

Offline

 

#33 Yesterday 08:45:49 am

ChangeAgent
Member
From:: Scotland
Registered: 2008-03-07
Posts: 292

Re: I have a script to shrink pictures that stopped working under 10.15.

Peavine, as to post 13.
It works and it does not.

It changes a png from 3.2MB to 590KB regardless of what we put in the sips dialog. 

And an 1.8MB jpeg reduces to 45kb with the script below. 

As said, it even works like this and has the same result.

Applescript:

on open draggeditems
   
   repeat with aFile in draggeditems
       set contents of aFile to quoted form of POSIX path of aFile & space
   end repeat
   
   do shell script "" & draggeditems
   
end open

Offline

 

#34 Yesterday 08:57:46 am

Yvan Koenig
Member
Registered: 2006-09-14
Posts: 4344

Re: I have a script to shrink pictures that stopped working under 10.15.

May you test this one and post what is reported?

Applescript:

property mode : 3 -- try with the values 1, 2, 3
-- 1 --> alias
-- 2 --> «class furl»
-- 3 --> POSIX Path
on open draggeditems
   tell application "Image Events" to launch
   
   repeat with currentFile in draggeditems
       if mode = 1 then
           set thePicture to currentFile as text
       else if mode = 2 then
           set thePicture to currentFile as «class furl» --> «class furl»
       else if mode = 3 then
           set thePicture to POSIX path of currentFile --> text
       end if
       tell application "Image Events"
           if mode = 1 then
               set openedFile to open file thePicture
           else
               set openedFile to open thePicture
           end if
           set fileLocation to the location of openedFile
           set fileName to the name of openedFile
           set origDimensions to dimensions of openedFile
           set origResolution to resolution of openedFile
           scale openedFile to size 800
           save openedFile with icon
           set newDimensions to dimensions of openedFile
           set newResolution to resolution of openedFile
           close openedFile
       end tell
       tell me to display dialog "origDimensions : " & my recolle(origDimensions, ", ") & linefeed & "origResolution : " & my recolle(origResolution, ", ") & linefeed & "newDimensions : " & my recolle(newDimensions, ", ") & linefeed & "newResolution : " & my recolle(newResolution, ", ")
       (*
       tell application "Finder"
           set the name of file fileName of fileLocation to (fileName)
       end tell
*)

   end repeat
end open

#=====
on recolle(l, d)
   local oTIDs, t
   set {oTIDs, AppleScript's text item delimiters} to {AppleScript's text item delimiters, d}
   set t to l as text
   set AppleScript's text item delimiters to oTIDs
   return t
end recolle
#=====

Here I got:
picture #1
origDimensions : 1725, 446
origResolution : 144,0, 144,0
newDimensions : 800,  207
newResolution : 144,0, 144,0

picture #2
origDimensions : 3104, 1746
origResolution : 72,0, 72,0
newDimensions : 800,  450
newResolution : 72,0, 72,0

Don't worry, the resolution is displayed with the local (comma) decimal separator.

Yvan KOENIG running High Sierra 10.13.6 in French (VALLAURIS, France) samedi 23 mai 2020 16:49:15

Offline

 

#35 Yesterday 08:59:44 am

peavine
Member
From:: Prescott, Arizona
Registered: 2018-09-04
Posts: 478

Re: I have a script to shrink pictures that stopped working under 10.15.

ChangeAgent wrote:

Peavine, as to post 13.
It works and it does not.

It changes a png from 3.2MB to 590KB regardless of what we put in the sips dialog. 

And an 1.8MB jpeg reduces to 45kb with the script below. 

As said, it even works like this and has the same result.

Applescript:

on open draggeditems
   
   repeat with aFile in draggeditems
       set contents of aFile to quoted form of POSIX path of aFile & space
   end repeat
   
   do shell script "" & draggeditems
   
end open



I don't know what happening then. Sorry I couldn't help.


2018 Mac mini - macOS Catalina

Online

 

#36 Yesterday 09:54:16 am

Yvan Koenig
Member
Registered: 2006-09-14
Posts: 4344

Re: I have a script to shrink pictures that stopped working under 10.15.

May you run :

Applescript:

on open draggeditems
   --set draggeditems to choose file of type {"public.jpeg"} with multiple selections allowed
   set text1 to my recolle(draggeditems, linefeed)
   repeat with aFile in draggeditems
       set contents of aFile to quoted form of POSIX path of aFile & space
   end repeat
   set text2 to my recolle(draggeditems, linefeed)
   
   display dialog text1 & linefeed & text2
   --do shell script "sips --resampleHeightWidthMax 800 " & draggeditems
end open
#=====

on recolle(l, d)
   local oTIDs, t
   set {oTIDs, AppleScript's text item delimiters} to {AppleScript's text item delimiters, d}
   set t to l as text
   set AppleScript's text item delimiters to oTIDs
   return t
end recolle

#=====

and report what you got ?


On my iMac (10.13.6) I got :

SSD 1000:Users:**********:Desktop:DSC_0257 - opposite.jpg
SSD 1000:Users:**********:Desktop:DSC_0257 - rotated.jpg
SSD 1000:Users:**********:Desktop:DSC_0257 - upDown.jpg
SSD 1000:Users:**********:Desktop:DSC_0257.JPG
'/Users/**********/Desktop/DSC_0257 - opposite.jpg'
'/Users/**********/Desktop/DSC_0257 - rotated.jpg'
'/Users/**********/Desktop/DSC_0257 - upDown.jpg'
'/Users/**********/Desktop/DSC_0257.JPG'

Yvan KOENIG running High Sierra 10.13.6 in French (VALLAURIS, France) samedi 23 mai 2020 17:53:39

Offline

 

#37 Yesterday 10:11:08 am

ChangeAgent
Member
From:: Scotland
Registered: 2008-03-07
Posts: 292

Re: I have a script to shrink pictures that stopped working under 10.15.

Yvan (post 34) here is what it reports for a jpeg pic:

origDimensions : 3264, 1836
origResolution : 72.0, 72.0
newDimensions : 800, 450
newResolution : 72.0, 72.0

however the pic went from 1.8 to 2.2 MB.  So, it shrunk its size as in dimensions but enlarged the size as in KB.

For a png a similar thing happens.  The size (MB) stays the same and it reports:

origDimensions : 1920, 1080
origResolution : 72.0, 72.0
newDimensions : 800, 450
newResolution : 72.0, 72.0

The aim of my original script was to redse KB.  So, the 1.8 MB became like 110 KB.

Offline

 

#38 Yesterday 10:14:03 am

ChangeAgent
Member
From:: Scotland
Registered: 2008-03-07
Posts: 292

Re: I have a script to shrink pictures that stopped working under 10.15.

Yvan as to the script in post 36, nothing happens.  Well I get a box to click.

OS 10.15 test:Users:e:Desktop:1 copy 5.png
'/Users/e/Desktop/1 copy 5.png'

Last edited by ChangeAgent (Yesterday 10:17:15 am)

Offline

 

#39 Yesterday 11:08:48 am

Yvan Koenig
Member
Registered: 2006-09-14
Posts: 4344

Re: I have a script to shrink pictures that stopped working under 10.15.

ChangeAgent wrote:

Yvan as to the script in post 36, nothing happens.  Well I get a box to click.

OS 10.15 test:Users:e:Desktop:1 copy 5.png
'/Users/e/Desktop/1 copy 5.png'



So, it did what it was supposed to do, If you look at the script in message 36, the call to SIPS was deliberately disabled.

Now that we know that the needed infos are correctly passed, try the version with the call to SIPS enabled:

Applescript:

on open draggeditems
   --set draggeditems to choose file of type {"public.jpeg"} with multiple selections allowed
   set text1 to my recolle(draggeditems, linefeed)
   repeat with aFile in draggeditems
       set contents of aFile to quoted form of POSIX path of aFile & space
   end repeat
   set text2 to my recolle(draggeditems, linefeed)
   
   display dialog text1 & linefeed & text2
   do shell script "sips --resampleHeightWidthMax 800 " & draggeditems
end open
#=====

on recolle(l, d)
   local oTIDs, t
   set {oTIDs, AppleScript's text item delimiters} to {AppleScript's text item delimiters, d}
   set t to l as text
   set AppleScript's text item delimiters to oTIDs
   return t
end recolle

#=====

Yvan KOENIG running High Sierra 10.13.6 in French (VALLAURIS, France) samedi 23 mai 2020 19:08:43

Offline

 

#40 Yesterday 11:10:35 am

Yvan Koenig
Member
Registered: 2006-09-14
Posts: 4344

Re: I have a script to shrink pictures that stopped working under 10.15.

ChangeAgent wrote:

Yvan (post 34) here is what it reports for a jpeg pic:

origDimensions : 3264, 1836
origResolution : 72.0, 72.0
newDimensions : 800, 450
newResolution : 72.0, 72.0

however the pic went from 1.8 to 2.2 MB.  So, it shrunk its size as in dimensions but enlarged the size as in KB.

For a png a similar thing happens.  The size (MB) stays the same and it reports:

origDimensions : 1920, 1080
origResolution : 72.0, 72.0
newDimensions : 800, 450
newResolution : 72.0, 72.0

The aim of my original script was to redse KB.  So, the 1.8 MB became like 110 KB.



May you send one or two of your pictures to my mail address : <koenigyvan <at> mac <dot> com>

Yvan KOENIG running High Sierra 10.13.6 in French (VALLAURIS, France) samedi 23 mai 2020 19:10:30

Offline

 

#41 Yesterday 11:36:20 pm

ChangeAgent
Member
From:: Scotland
Registered: 2008-03-07
Posts: 292

Re: I have a script to shrink pictures that stopped working under 10.15.

Yvan Koenig wrote:

Now that we know that the needed infos are correctly passed, try the version with the call to SIPS enabled:



Same result as before.

Offline

 

#42 Today 12:03:28 am

ChangeAgent
Member
From:: Scotland
Registered: 2008-03-07
Posts: 292

Re: I have a script to shrink pictures that stopped working under 10.15.

Yvan Koenig wrote:

May you send one or two of your pictures


send.

Offline

 

#43 Today 02:15:00 am

Yvan Koenig
Member
Registered: 2006-09-14
Posts: 4344

Re: I have a script to shrink pictures that stopped working under 10.15.

Thank you.

Really simple.
Your jpeg is one of the 'corrupted' ones which are available since a few months.
When I looked at its contents with an hexadecimal editor I found a large number of null bytes at its end.
These bytes prevent SIPS or Image Events to achieve their job.
I removed these extraneous bytes so, the original file (1754025 bytes) became a 1560661 bytes one.
When I treated it with SIPS I got a 52949 bytes one.

Some days ago I wrote a script designed to clean such 'corrupted' files.
Shane Stanley gave me a more efficient one.
Here it is.

Yvan,

Here's another approach. It's still a bit on the dirty side, but I see the first file I tried contained FFD900 more than once. The problem is to avoid accidentally running the code on a file that has already been trimmed. There's probably a more efficient way, but it shouldn't be too bad:

Applescript:

use AppleScript version "2.5" -- macOS 10.11 or later
use framework "Foundation"
use scripting additions

set theFile to choose file
--search for FFD900
set b64String to "/9kA" -- FFD900 in Base64
set b64Data to current application's NSData's alloc()'s initWithBase64EncodedString:b64String options:0
set theData to current application's NSData's dataWithContentsOfURL:theFile
set dataLen to theData's |length|()
set theRange to theData's rangeOfData:b64Data options:(current application's NSDataSearchBackwards) range:{0, dataLen}
if |length| of theRange = 3 then
   -- make sure only nulls after it by making base64 string of the rest, then looking for other than A or = in it
   set maxRange to current application's NSMaxRange(theRange)
   set endData to theData's subdataWithRange:{maxRange + 1, dataLen - maxRange - 1}
   set endB64 to (endData's base64EncodedStringWithOptions:0)
   set newRange to endB64's rangeOfString:"[^A=]" options:(current application's NSRegularExpressionSearch)
   if |length| of newRange is 0 then
       -- we know it's only nulls
       set eof theFile to ((location of theRange) + 2)
   end if
end if

On my side I encapsulated it in a script which filter Jpegs in every cases in droplet as well as in applet.

Applescript:

use AppleScript version "2.5" -- macOS 10.11 or later
use framework "Foundation"
use scripting additions

on run
   set theFiles to choose file with prompt "Sélectionner un ou plusieurs fichiers jpg" of type {"public.jpeg"} with multiple selections allowed
   repeat with aFile in theFiles
       my removeGarbage(aFile)
   end repeat
end run

on open theFiles -- alas list of drag & dropped items
   tell application "System Events"
       repeat with aFile in theFiles
           if type identifier of aFile is "public.jpeg" then my removeGarbage(aFile)
       end repeat
   end tell
end open

on removeGarbage(theFile)
   -- handler written by Shane Stanley on 2020/04/30
   --search for FFD900
   set b64String to "/9kA" -- FFD900 in Base64
   set b64Data to current application's NSData's alloc()'s initWithBase64EncodedString:b64String options:0
   set theData to current application's NSData's dataWithContentsOfURL:theFile
   set dataLen to theData's |length|()
   set theRange to theData's rangeOfData:b64Data options:(current application's NSDataSearchBackwards) range:{0, dataLen}
   if |length| of theRange = 3 then
       -- make sure only nulls after it by making base64 string of the rest, then looking for other than A or = in it
       set maxRange to current application's NSMaxRange(theRange)
       set endData to theData's subdataWithRange:{maxRange + 1, dataLen - maxRange - 1}
       set endB64 to (endData's base64EncodedStringWithOptions:0)
       set newRange to endB64's rangeOfString:"[^A=]" options:(current application's NSRegularExpressionSearch)
       if |length| of newRange is 0 then
           -- we know it's only nulls
           set eof theFile to ((location of theRange) + 2)
       end if
   end if
end removeGarbage

In an other message, Shane wrote : If you save it from Script Debugger, you will see in the Resources pane that you can restrict drag-and-drop to just jpeg files.


Try it and let all of us know if this time you get the wanted result.

Yvan KOENIG running High Sierra 10.13.6 in French (VALLAURIS, France) dimanche 24 mai 2020 10:08:38

PS: not sure that the problem is solved for you. Here, when I apply SIPs on your original file, it's correctly reduced.

Last edited by Yvan Koenig (Today 02:54:11 am)

Offline

 

#44 Today 04:12:00 am

ChangeAgent
Member
From:: Scotland
Registered: 2008-03-07
Posts: 292

Re: I have a script to shrink pictures that stopped working under 10.15.

Yvan good morning.

I am not able to make it work.  I am now testing under 10.13, like you.

Yes the script shrinks the picture and always to 229MB.

I cannot control the size in any way, I tried numbers from 1 to 50000 and the output size is always the same.

So I started testing.

As you see in the script below I can disable almost of all of it and it still works.


Applescript:


on open draggeditems
   --set draggeditems to choose file of type {"public.jpeg"} with multiple selections allowed
   --set text1 to my recolle(draggeditems, linefeed)
   --repeat with aFile in draggeditems
   --set contents of aFile to quoted form of POSIX path of aFile & space
   --end repeat
   --set text2 to my recolle(draggeditems, linefeed)
   
   -- display dialog text1 & linefeed & text2
   -- do shell script "sips --resampleHeightWidthMax 50000 " & draggeditems
end open
#=====

--on recolle(l, d)
--local oTIDs, t
--set {oTIDs, AppleScript's text item delimiters} to {AppleScript's text item delimiters, d}
--set t to l as text
--set AppleScript's text item delimiters to oTIDs
--return t
--end recolle

#=====

This is not possible.  So I pasted the clean text in a new one and it does not work.

Applescript:


on open draggeditems
end open

Now, I am not an expert here, but something is funny.  I would guess that there is code that keeps ‘hanging’ in the script.  Or?

What do you think and could this be the cause of the challenges I have with the script?


Now my original script:

Applescript:


tell application "Image Events"
launch
end tell
on open draggeditems
repeat with currentFile in draggeditems
tell application "Image Events"
set openedFile to open (currentFile as alias)
--Part 3:
set fileLocation to the location of openedFile
set fileName to the name of openedFile
--Part 4:
scale openedFile to size 800
save openedFile with icon
close openedFile
end tell
--Part 5:
tell application "Finder"
set the name of file fileName of fileLocation to ¬
(fileName)
end tell
end repeat
end open

It still works but I can not influence the size (like in the other proposed script here) anymore.  I had 3 scripts, where I had different numbers (here 800) like 700 and 100.  This would influence the size.  And it still does if I use the originals.  But as soon as I copy to a new file or change the number it goes to 54 mb.

Offline

 

#45 Today 06:20:55 am

Yvan Koenig
Member
Registered: 2006-09-14
Posts: 4344

Re: I have a script to shrink pictures that stopped working under 10.15.

I can't guess what you made wrongly but you did.

Please click the button [Open this Scriplet in your Editor:] which appears below:
and save this script as "resize to 800.app" with absolutely no change !

Applescript:

-- save this one as "resize to 800.app"
-- I disabled useless instructions

on open draggeditems
   tell application "Image Events" to launch
   repeat with currentFile in draggeditems
       tell application "Image Events"
           set openedFile to open file (currentFile as string)
           --Part 3:
           --set fileLocation to the location of openedFile
           --set fileName to the name of openedFile
           --Part 4:
           scale openedFile to size 800
           save openedFile with icon
           close openedFile
       end tell
       (*
       --Part 5:
tell application "Finder"
set the name of file fileName of fileLocation to ¬
(fileName)
end tell
       *)

   end repeat
end open

Please click the button [Open this Scriplet in your Editor:] which appears below:
and save this script as "resize to 1200.app" with absolutely no change !

Applescript:

-- save this one as "resize to 1200.app"
-- I disabled useless instructions

on open draggeditems
   tell application "Image Events" to launch
   repeat with currentFile in draggeditems
       tell application "Image Events"
           set openedFile to open file (currentFile as string)
           --Part 3:
           --set fileLocation to the location of openedFile
           --set fileName to the name of openedFile
           --Part 4:
           scale openedFile to size 1200
           save openedFile with icon
           close openedFile
       end tell
       (*
       --Part 5:
tell application "Finder"
set the name of file fileName of fileLocation to ¬
(fileName)
end tell
       *)

   end repeat
end open

EDITED FROM HERE


Please click the button [Open this Scriplet in your Editor:] which appears below:
and save this script as "resize to 1600.app" with absolutely no change !

Applescript:

-- save this one as "resize to 1600.app"
-- I disabled useless instructions

on open draggeditems
   tell application "Image Events" to launch
   repeat with currentFile in draggeditems
       tell application "Image Events"
           set openedFile to open file (currentFile as string)
           --Part 3:
           --set fileLocation to the location of openedFile
           --set fileName to the name of openedFile
           --Part 4:
           scale openedFile to size 1600
           save openedFile with icon
           close openedFile
       end tell
       (*
       --Part 5:
tell application "Finder"
set the name of file fileName of fileLocation to ¬
(fileName)
end tell
       *)

   end repeat
end open

Please click the button [Open this Scriplet in your Editor:] which appears below:
and save this script as "three sizes.scpt" with absolutely no change !

UNTIL HERE

Applescript:

property mode : 1 -- try with the values 1, 2, 3
-- 1 --> alias
-- 2 --> «class furl»
-- 3 --> POSIX Path
--on open draggeditems

set draggedItems to choose file of type {"public.jpeg"} with multiple selections allowed
tell application "Image Events" to launch

repeat with currentFile in draggedItems
   if mode = 1 then
       set thePicture to currentFile as text
   else if mode = 2 then
       set thePicture to currentFile as «class furl» --> «class furl»
   else if mode = 3 then
       set thePicture to POSIX path of currentFile --> text
   end if
   
   set origSizeXXX to size of (info for currentFile)
   tell application "Image Events"
       if mode = 1 then
           set openedFile to open file thePicture
       else
           set openedFile to open thePicture
       end if
       --set fileLocation to the location of openedFile
       --set fileName to the name of openedFile
       set origDimensions to dimensions of openedFile
       set origResolution to resolution of openedFile
       scale openedFile to size 800
       save openedFile with icon
       set newDimensions to dimensions of openedFile
       set newResolution to resolution of openedFile
       close openedFile
   end tell
   set newSize800 to size of (info for currentFile)
   tell me to display dialog "origSizeXXX : " & origSizeXXX & " bytes" & linefeed & "origDimensions : " & my recolle(origDimensions, ", ") & linefeed & "origResolution : " & my recolle(origResolution, ", ") & linefeed & "newDimensions : " & my recolle(newDimensions, ", ") & linefeed & "newResolution : " & my recolle(newResolution, ", ") & linefeed & "newSize800 : " & newSize800 & " bytes" & linefeed
   
   set origSize800 to size of (info for currentFile)
   tell application "Image Events"
       if mode = 1 then
           set openedFile to open file thePicture
       else
           set openedFile to open thePicture
       end if
       --set fileLocation to the location of openedFile
       --set fileName to the name of openedFile
       set origDimensions to dimensions of openedFile
       set origResolution to resolution of openedFile
       scale openedFile to size 1600
       save openedFile with icon
       set newDimensions to dimensions of openedFile
       set newResolution to resolution of openedFile
       close openedFile
   end tell
   set newSize1600 to size of (info for currentFile)
   tell me to display dialog "origSize800 : " & origSize800 & " bytes" & linefeed & "origDimensions : " & my recolle(origDimensions, ", ") & linefeed & "origResolution : " & my recolle(origResolution, ", ") & linefeed & "newDimensions : " & my recolle(newDimensions, ", ") & linefeed & "newResolution : " & my recolle(newResolution, ", ") & linefeed & "newSize1600 : " & newSize1600 & " bytes" & linefeed
   
   set origSize1600 to size of (info for currentFile)
   tell application "Image Events"
       if mode = 1 then
           set openedFile to open file thePicture
       else
           set openedFile to open thePicture
       end if
       --set fileLocation to the location of openedFile
       --set fileName to the name of openedFile
       set origDimensions to dimensions of openedFile
       set origResolution to resolution of openedFile
       scale openedFile to size 3200
       save openedFile with icon
       set newDimensions to dimensions of openedFile
       set newResolution to resolution of openedFile
       close openedFile
   end tell
   set newSize3200 to size of (info for currentFile)
   tell me to display dialog "origSize1600 : " & origSize1600 & " bytes" & linefeed & "origDimensions : " & my recolle(origDimensions, ", ") & linefeed & "origResolution : " & my recolle(origResolution, ", ") & linefeed & "newDimensions : " & my recolle(newDimensions, ", ") & linefeed & "newResolution : " & my recolle(newResolution, ", ") & linefeed & "newSize3200 : " & newSize3200 & " bytes" & linefeed
end repeat
--end open

#=====
on recolle(l, d)
   local oTIDs, t
   set {oTIDs, AppleScript's text item delimiters} to {AppleScript's text item delimiters, d}
   set t to l as text
   set AppleScript's text item delimiters to oTIDs
   return t
end recolle
#=====

It's a slightly edited version of the one which I sent to your mailbox.

Run it from the Script Editor without any change.
You are supposed to get this log history:

Applescript:


Please don't click the button [Open this Scriplet in your Editor:],
this is not a script but a log history !
tell application "Script Editor"
   choose file of type {"public.jpeg"} with multiple selections allowed
       --> {alias "SSD 1000:Users:**********:Desktop:2 copy 2.jpg"}
end tell
tell application "Image Events"
   launch
end tell
tell current application
   info for alias "SSD 1000:Users:**********:Desktop:2 copy 2.jpg"
       --> {name:"2 copy 2.jpg", creation date:date "mercredi 6 mai 2020 à 17:16:56", modification date:date "mercredi 6 mai 2020 à 17:16:56", size:1754025, folder:false, alias:false, package folder:false, visible:true, extension hidden:false, name extension:"jpg", displayed name:"2 copy 2.jpg", default application:alias "SSD 1000:Applications:Preview.app:", kind:"Image JPEG", 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 "SSD 1000:Users:**********:Desktop:2 copy 2.jpg"
       --> image "2 copy 2.jpg"
   get dimensions of image "2 copy 2.jpg"
       --> {3264, 1836}
   get resolution of image "2 copy 2.jpg"
       --> {72.0, 72.0}
   scale image "2 copy 2.jpg" to size 800
   save image "2 copy 2.jpg" with icon
       --> file "SSD 1000:Users:**********:Desktop:2 copy 2.jpg"
   get dimensions of image "2 copy 2.jpg"
       --> {800, 450}
   get resolution of image "2 copy 2.jpg"
       --> {72.0, 72.0}
   close image "2 copy 2.jpg"
end tell
tell current application
   info for alias "SSD 1000:Users:**********:Desktop:2 copy 2.jpg"
       --> {name:"2 copy 2.jpg", creation date:date "dimanche 24 mai 2020 à 13:46:38", modification date:date "dimanche 24 mai 2020 à 13:46:38", size:52949, folder:false, alias:false, package folder:false, visible:true, extension hidden:false, name extension:"jpg", displayed name:"2 copy 2.jpg", default application:alias "SSD 1000:Applications:Preview.app:", kind:"Image JPEG", file type:", file creator:", type identifier:"public.jpeg", locked:false, busy status:false, short version:"", long version:""}
end tell
tell application "Script Editor"
   display dialog "origSizeXXX : 1754025 bytes
origDimensions : 3264, 1836
origResolution : 72,0, 72,0
newDimensions : 800, 450
newResolution : 72,0, 72,0
newSize800 : 52949 bytes
"

       --> {button returned:"OK"}
end tell
tell current application
   info for alias "SSD 1000:Users:**********:Desktop:2 copy 2.jpg"
       --> {name:"2 copy 2.jpg", creation date:date "dimanche 24 mai 2020 à 13:46:38", modification date:date "dimanche 24 mai 2020 à 13:46:38", size:52949, folder:false, alias:false, package folder:false, visible:true, extension hidden:false, name extension:"jpg", displayed name:"2 copy 2.jpg", default application:alias "SSD 1000:Applications:Preview.app:", kind:"Image JPEG", 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 "SSD 1000:Users:**********:Desktop:2 copy 2.jpg"
       --> image "2 copy 2.jpg"
   get dimensions of image "2 copy 2.jpg"
       --> {800, 450}
   get resolution of image "2 copy 2.jpg"
       --> {72.0, 72.0}
   scale image "2 copy 2.jpg" to size 1600
   save image "2 copy 2.jpg" with icon
       --> file "SSD 1000:Users:**********:Desktop:2 copy 2.jpg"
   get dimensions of image "2 copy 2.jpg"
       --> {1600, 900}
   get resolution of image "2 copy 2.jpg"
       --> {72.0, 72.0}
   close image "2 copy 2.jpg"
end tell
tell current application
   info for alias "SSD 1000:Users:**********:Desktop:2 copy 2.jpg"
       --> {name:"2 copy 2.jpg", creation date:date "dimanche 24 mai 2020 à 13:46:42", modification date:date "dimanche 24 mai 2020 à 13:46:42", size:126642, folder:false, alias:false, package folder:false, visible:true, extension hidden:false, name extension:"jpg", displayed name:"2 copy 2.jpg", default application:alias "SSD 1000:Applications:Preview.app:", kind:"Image JPEG", file type:", file creator:", type identifier:"public.jpeg", locked:false, busy status:false, short version:"", long version:""}
end tell
tell application "Script Editor"
   display dialog "origSize800 : 52949 bytes
origDimensions : 800, 450
origResolution : 72,0, 72,0
newDimensions : 1600, 900
newResolution : 72,0, 72,0
newSize1600 : 126642 bytes
"

       --> {button returned:"OK"}
end tell
tell current application
   info for alias "SSD 1000:Users:**********:Desktop:2 copy 2.jpg"
       --> {name:"2 copy 2.jpg", creation date:date "dimanche 24 mai 2020 à 13:46:42", modification date:date "dimanche 24 mai 2020 à 13:46:42", size:126642, folder:false, alias:false, package folder:false, visible:true, extension hidden:false, name extension:"jpg", displayed name:"2 copy 2.jpg", default application:alias "SSD 1000:Applications:Preview.app:", kind:"Image JPEG", 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 "SSD 1000:Users:**********:Desktop:2 copy 2.jpg"
       --> image "2 copy 2.jpg"
   get name of image "2 copy 2.jpg"
       --> "2 copy 2.jpg"
   get dimensions of image "2 copy 2.jpg"
       --> {1600, 900}
   get resolution of image "2 copy 2.jpg"
       --> {72.0, 72.0}
   scale image "2 copy 2.jpg" to size 3200
   save image "2 copy 2.jpg" with icon
       --> file "SSD 1000:Users:**********:Desktop:2 copy 2.jpg"
   get dimensions of image "2 copy 2.jpg"
       --> {3200, 1800}
   get resolution of image "2 copy 2.jpg"
       --> {72.0, 72.0}
   close image "2 copy 2.jpg"
end tell
tell current application
   info for alias "SSD 1000:Users:**********:Desktop:2 copy 2.jpg"
       --> {name:"2 copy 2.jpg", creation date:date "dimanche 24 mai 2020 à 13:46:44", modification date:date "dimanche 24 mai 2020 à 13:46:44", size:320141, folder:false, alias:false, package folder:false, visible:true, extension hidden:false, name extension:"jpg", displayed name:"2 copy 2.jpg", default application:alias "SSD 1000:Applications:Preview.app:", kind:"Image JPEG", file type:", file creator:", type identifier:"public.jpeg", locked:false, busy status:false, short version:"", long version:""}
end tell
tell application "Script Editor"
   display dialog "origSize1600 : 126642 bytes
origDimensions : 1600, 900
origResolution : 72,0, 72,0
newDimensions : 3200, 1800
newResolution : 72,0, 72,0
newSize3200 : 320141 bytes
"

       --> {button returned:"OK"}
end tell

Yvan KOENIG running High Sierra 10.13.6 in French (VALLAURIS, France) dimanche 24 mai 2020 14:20:46

Last edited by Yvan Koenig (Today 07:00:35 am)

Offline

 

#46 Today 06:32:02 am

Yvan Koenig
Member
Registered: 2006-09-14
Posts: 4344

Re: I have a script to shrink pictures that stopped working under 10.15.

ChangeAgent wrote:

Yvan good morning.

I am not able to make it work.  I am now testing under 10.13, like you.

Yes the script shrinks the picture and always to 229MB.

I cannot control the size in any way, I tried numbers from 1 to 50000 and the output size is always the same.

So I started testing.

As you see in the script below I can disable almost of all of it and it still works.


Applescript:


on open draggeditems
   --set draggeditems to choose file of type {"public.jpeg"} with multiple selections allowed
   --set text1 to my recolle(draggeditems, linefeed)
   --repeat with aFile in draggeditems
   --set contents of aFile to quoted form of POSIX path of aFile & space
   --end repeat
   --set text2 to my recolle(draggeditems, linefeed)
   
   -- display dialog text1 & linefeed & text2
   -- do shell script "sips --resampleHeightWidthMax 50000 " & draggeditems
end open
#=====

--on recolle(l, d)
--local oTIDs, t
--set {oTIDs, AppleScript's text item delimiters} to {AppleScript's text item delimiters, d}
--set t to l as text
--set AppleScript's text item delimiters to oTIDs
--return t
--end recolle

#=====



The script above does absolutely nothing !
So I don't understand what means your statement :  and it still works.


This is not possible.  So I pasted the clean text in a new one and it does not work.

Applescript:


on open draggeditems
end open



The script above, which is in fact exactly the same than the first one, does absolutely nothing !
So I don't understand what means your statement :  and it does not work.


Yvan KOENIG running High Sierra 10.13.6 in French (VALLAURIS, France) dimanche 24 mai 2020 14:30:28

Offline

 

#47 Today 06:48:11 am

ChangeAgent
Member
From:: Scotland
Registered: 2008-03-07
Posts: 292

Re: I have a script to shrink pictures that stopped working under 10.15.

to post 45

Yvan greetings, me reporting.  I saved all 3 of them.  800 and 1200 work if I drop a file on it and give different sizes.

1600 does not work saved as an app if I drop a file on it.  It does nothing.

If I however run it, it gives me the change to select a file and gives me 3 boxes.


origSizeXXX : 1754025 bytes
origDimensions : 3264, 1836
origResolution : 72.0, 72.0
newDimensions : 800, 450
newResolution : 72.0, 72.0
newSize800 : 52949 bytes


origSize800 : 52949 bytes
origDimensions : 800, 450
origResolution : 72.0, 72.0
newDimensions : 800, 450
newResolution : 72.0, 72.0
newSize1600 : 126642 bytes



origSize1600 : 126642 bytes
origDimensions : 1600, 900
origResolution : 72.0, 72.0
newDimensions : 3200, 1800
newResolution : 72.0, 72.0
newSize3200 : 320141 bytes


and shrinks it to 320KB.

I suspect we arrived, did we not?  I need to test later under 10.15, and will report.

Question, I now run them without repair.  I assume there is no need for this?

Offline

 

#48 Today 06:53:54 am

ChangeAgent
Member
From:: Scotland
Registered: 2008-03-07
Posts: 292

Re: I have a script to shrink pictures that stopped working under 10.15.

Yvan Koenig wrote:


Applescript:


on open draggeditems
   --set draggeditems to choose file of type {"public.jpeg"} with multiple selections allowed
   --set text1 to my recolle(draggeditems, linefeed)
   --repeat with aFile in draggeditems
   --set contents of aFile to quoted form of POSIX path of aFile & space
   --end repeat
   --set text2 to my recolle(draggeditems, linefeed)
   
   -- display dialog text1 & linefeed & text2
   -- do shell script "sips --resampleHeightWidthMax 50000 " & draggeditems
end open
#=====

--on recolle(l, d)
--local oTIDs, t
--set {oTIDs, AppleScript's text item delimiters} to {AppleScript's text item delimiters, d}
--set t to l as text
--set AppleScript's text item delimiters to oTIDs
--return t
--end recolle

#=====

The script above does absolutely nothing !
So I don't understand what means your statement :  and it still works.



correct and it still shrunk the picture. 

this is what I did.  I opened the app with SE, took all the lines out, saved it as the original app and it worked as before.  it should not but it did.

do I understand it?  no I do not.

a bug?  possibly.

Offline

 

#49 Today 07:04:30 am

Yvan Koenig
Member
Registered: 2006-09-14
Posts: 4344

Re: I have a script to shrink pictures that stopped working under 10.15.

ChangeAgent wrote:

to post 45

Yvan greetings, me reporting.  I saved all 3 of them.  800 and 1200 work if I drop a file on it and give different sizes.

1600 does not work saved as an app if I drop a file on it.  It does nothing.


My fault,
I edited message #45 to repair my error.

If I however run it, it gives me the change to select a file and gives me 3 boxes.


origSizeXXX : 1754025 bytes
origDimensions : 3264, 1836
origResolution : 72.0, 72.0
newDimensions : 800, 450
newResolution : 72.0, 72.0
newSize800 : 52949 bytes


origSize800 : 52949 bytes
origDimensions : 800, 450
origResolution : 72.0, 72.0
newDimensions : 800, 450
newResolution : 72.0, 72.0
newSize1600 : 126642 bytes



origSize1600 : 126642 bytes
origDimensions : 1600, 900
origResolution : 72.0, 72.0
newDimensions : 3200, 1800
newResolution : 72.0, 72.0
newSize3200 : 320141 bytes


and shrinks it to 320KB.

I suspect we arrived, did we not?  I need to test later under 10.15, and will report.

Question, I now run them without repair.  I assume there is no need for this?

Offline

 

#50 Today 07:17:09 am

ChangeAgent
Member
From:: Scotland
Registered: 2008-03-07
Posts: 292

Re: I have a script to shrink pictures that stopped working under 10.15.

OK testing in 10.15.  same jpeg as before.

Without cleaning first.  1.8MB > run on 800 > shows briefly 45kb > ends at 2.2GB > icon stays the same.

With cleaning first.  1.8MB > clean > 1.6MB > run on 800 > shows briefly 45kb > ends at 2.2GB > icon has gotten larger.

So runs clearly happily under 10.13 not under 10.15.

Offline

 

Board footer

Powered by FluxBB

RSS (new topics) RSS (active topics)