Copying pictures

About SheepShaver, a PPC Mac emulator for Windows, MacOS X, and Linux that can run System 7.5.3 to MacOS 9.0.4.

Moderators: Cat_7, Ronald P. Regensburg, ClockWise

emendelson
Forum All-Star
Posts: 1706
Joined: Tue Oct 14, 2008 12:12 am

Re: Copying pictures

Post by emendelson »

Ronald P. Regensburg wrote: Mon Aug 30, 2021 7:10 pm In the info.plist file is a long list of privacy items.

...

I suppose only the first one is needed.
Those are added by Script Debugger, but I can set Script Debugger to remove all of them except the first, as you suggest. Probably won't have any effect on this issue...
User avatar
mabam
Master Emulator
Posts: 497
Joined: Wed Apr 10, 2013 9:32 am

Re: Copying pictures

Post by mabam »

Ronald P. Regensburg wrote: Mon Aug 30, 2021 7:01 pm
mabam wrote: Mon Aug 30, 2021 4:40 pmFiles and Folders only shows apps which were first added to Full Disk Access.
All apps in Full Disk Access also show up in Files and Folders, but many apps in Files and Folders, the ones that have access to specific folders and volumes, are not in Full Disk Access. I suppose they are added when the user allows access when asked while running the app.
I see. Sorry for my wrong statement and thanks for correction.
User avatar
mabam
Master Emulator
Posts: 497
Joined: Wed Apr 10, 2013 9:32 am

Re: Copying pictures

Post by mabam »

Another thing:
The developer of Deark has added an option for us: "-opt pict:decodeqt".
See https://github.com/jsummers/deark/issue ... -908604441.

Changing the line

Code: Select all

set dearkResponse to paragraph -1 of (do shell script dearkPath & " -l -maxfiles 1 ~/Documents/clipboardConvFile." & sourceExtension)
to

Code: Select all

set dearkResponse to paragraph -1 of (do shell script dearkPath & " -l -maxfiles 1 -opt pict:decodeqt ~/Documents/clipboardConvFile." & sourceExtension)

and the line

Code: Select all

do shell script dearkPath & " ~/Documents/clipboardConvFile." & sourceExtension & " -t ~/Documents/clipboardConvFile." & destExtension
to

Code: Select all

do shell script dearkPath & " -opt pict:decodeqt ~/Documents/clipboardConvFile." & sourceExtension & " -t ~/Documents/clipboardConvFile." & destExtension

should make our script more efficient for PICT files with multiple containers.
emendelson
Forum All-Star
Posts: 1706
Joined: Tue Oct 14, 2008 12:12 am

Re: Copying pictures

Post by emendelson »

I'm traveling this week and may not be able to work more on this for a few days, but I've done this:

I downloaded the latest deark code and built the executable; and I made the changes that mabam suggested for the code (for the dialog boxes, I simply told the application to "activate" before displaying the dialog; that seems to work in my other applications).

Unfortunately, when I run the code I get this error message:
Deark error:

Error: Can't read /Users/edward/Documents/clipboardConvFile.format: No such file or directory
I don't see how the extension "format" got in there so I don't know how to fix it. Mabam, am I doing something wrong (as is likely)? Here's my code:

Code: Select all

use AppleScript version "2.4" -- Yosemite (10.10) or later
use scripting additions
use framework "Foundation" -- needed to check keyboard state
use framework "AppKit" -- needed to check keyboard state

-- to show image preview, either change next to true or
-- add "show" to the name of the app (as in "ConvertClipboardPICT Show")
property showImage : true

on run {}
	
	set myName to name of me as string
	
	if item 1 of item 1 of (clipboard info) as string is not "picture" then
		activate
		display dialog "No PICT data on the clipboard." buttons {"OK"} giving up after 5 with title myName
		error number -128
	end if
	
	-- next two lines get permissions settled at the start
	tell application "Finder" to count windows
	tell application "System Events" to count windows
	
	-- next try block gets the permissions dialog before anything else
	try
		do shell script "ls" & space & "~/Documents/clipboardConvFile.*"
	end try
	
	if myName contains "Show" then set showImage to true
	if (myName contains "Key" or myName contains "Option") then
		if (((current application's NSEvent's modifierFlags()) div 524288) mod 2) > 0 then -- 524288 = current application's NSAlternateKeyMask
			set showImage to true
		end if
	end if
	
	set myPath to POSIX path of (path to me)
	set helpers to myPath & "Contents/Resources/Helpers/"
	set dearkPath to quoted form of (helpers & "deark")
	set impbcopyPath to quoted form of (helpers & "impbcopy")
	
	set pictHeader to «data PICT0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000»
	
	try
		set clipFile to POSIX path of (path to documents folder as text) & "clipboardConvFile.pct"
		set theOpenedFile to open for access clipFile with write permission
		set eof of theOpenedFile to 0 -- Clear file content
		write pictHeader to theOpenedFile starting at eof
		write (the clipboard as picture) to theOpenedFile
		close access theOpenedFile
	on error err
		try
			close access theOpenedFile
		end try
		activate
		display dialog err
		error number -128
	end try
	
	try
		set sourceExtension to "pct"
		repeat
			set dearkResponse to paragraph -1 of (do shell script dearkPath & " -l -maxfiles 1 -opt pict:decodeqt ~/Documents/clipboardConvFile." & sourceExtension)
			if dearkResponse is "No files found to extract!" then
				exit repeat
			else
				set destExtension to word -1 of dearkResponse
			end if
			do shell script dearkPath & " ~/Documents/clipboardConvFile." & sourceExtension & " -t ~/Documents/clipboardConvFile." & destExtension
			set sourceExtension to destExtension
		end repeat
	on error err
		if err contains "permission error" then
			activate
			display dialog "The converter program was unable to convert the image." buttons ("OK") giving up after 5 with title myName
			try
				do shell script "rm -f" & space & "~/Documents/clipboardConvFile.*"
			end try
			error number -128
		else
			activate
			display dialog "Deark error:" & return & return & err
		end if
	end try
	
	try
		if destExtension is in {"png", "tif", "jpg", "gif", "bmp"} then
			if destExtension is "png" then
				set imgFormat to "PNGf"
			else if destExtension is "tif" then
				set imgFormat to "TIFF"
			else if destExtension is "jpg" then
				set imgFormat to "JPEG"
			else if destExtension is "gif" then
				set imgFormat to "GIFf"
			else if destExtension is "bmp" then
				set imgFormat to "BMPf"
			end if
			set the clipboard to {picture:(read (POSIX path of (path to documents folder as text) & "clipboardConvFile." & destExtension) as imgFormat)}
		else
			do shell script impbcopyPath & space & "~/Documents/clipboardConvFile." & destExtension -- Copies the image to the clipboard as TIFF.
			set the clipboard to (the clipboard as «class PNGf») -- Copies a compressed PNG version of the image to the clipboard.
		end if
	on error err
		set trashDialog to ""
		try
			set trashDialog to return & return & "Move the converted image file out of the trash if needed."
			tell application "Finder" to move file ((path to home folder as text) & "clipboardConvFile." & destExtension) as text to trash
		on error
			set trashDialog to ""
		end try
		activate
		display dialog "Could not copy the converted image to the clipboard." & trashDialog & return & return & err buttons {"OK"} giving up after 5 with title myName
		try
			do shell script "rm -f" & space & "~/Documents/clipboardConvFile.*"
		end try
	end try
	
	if showImage is true then
		set tempFile to "~/Documents/clipboardConvFile." & destExtension
		do shell script "/usr/bin/qlmanage -p" & space & tempFile & space & "> /dev/null 2>&1 &"
		
		set counter to 0
		repeat until counter is 5
			delay 0.25
			set counter to counter + 0.25
			tell application "System Events"
				if (name of every process) does not contain "qlmanage" then
					exit repeat
				end if
			end tell
		end repeat
		if counter is 5 then
			tell application "qlmanage" to quit
		end if
		
	end if
	try
		do shell script "rm -f" & space & "~/Documents/clipboardConvFile.*"
	end try
	
end run

User avatar
mabam
Master Emulator
Posts: 497
Joined: Wed Apr 10, 2013 9:32 am

Re: Copying pictures

Post by mabam »

I’m not in front of my computer right now so I haven’t tested, but you’re missing “-opt pict:decodeqt” in the second Deark line.
emendelson
Forum All-Star
Posts: 1706
Joined: Tue Oct 14, 2008 12:12 am

Re: Copying pictures

Post by emendelson »

I don't know how I could have missed that, since I thought I had merely Selected All and copied and pasted, but of course you're right. It works perfectly now, I think, and I've notarized and uploaded read-only and editable versions. Same link:

http://www.columbia.edu/~em36/ConvertClipboardPICT.zip

EDIT: The zip that I uploaded a few minutes showed the wrong title in dialog boxes; now fixed.
User avatar
mabam
Master Emulator
Posts: 497
Joined: Wed Apr 10, 2013 9:32 am

Re: Copying pictures

Post by mabam »

Thanks for uploading the new version. Conversion runs fine here. The option key or changing the app’s name still doesn’t do anything for me, though.

With the new Deark option it would be better to remove the repeat loop. I realised that the way it is now was a quick “fix” by me. It works but doesn’t really make sense logically.

I’ll be gone for a few days now but should be able to have a look into it somewhere next week.
emendelson
Forum All-Star
Posts: 1706
Joined: Tue Oct 14, 2008 12:12 am

Re: Copying pictures

Post by emendelson »

Again, thank you. I won't try to sort out the problems with the name of the app until you look at the code again.
User avatar
mabam
Master Emulator
Posts: 497
Joined: Wed Apr 10, 2013 9:32 am

Re: Copying pictures

Post by mabam »

mabam wrote: Thu Sep 02, 2021 10:50 pm With the new Deark option it would be better to remove the repeat loop. I realised that the way it is now was a quick “fix” by me. It works but doesn’t really make sense logically.

I’ll be gone for a few days now but should be able to have a look into it somewhere next week.

Here we go. Substitute

Code: Select all

		set sourceExtension to "pct"
		repeat
			set dearkResponse to paragraph -1 of (do shell script dearkPath & " -l -maxfiles 1 -opt pict:decodeqt ~/Documents/clipboardConvFile." & sourceExtension)
			if dearkResponse is "No files found to extract!" then
				exit repeat
			else
				set destExtension to word -1 of dearkResponse
			end if
			do shell script dearkPath & " ~/Documents/clipboardConvFile." & sourceExtension & " -t ~/Documents/clipboardConvFile." & destExtension
			set sourceExtension to destExtension
		end repeat
by

Code: Select all

		set destExtension to word -1 of (do shell script dearkPath & " -l -maxfiles 1 -opt pict:decodeqt ~/Documents/clipboardConvFile.pct")
		do shell script dearkPath & " ~/Documents/clipboardConvFile.pct -t ~/Documents/clipboardConvFile." & destExtension
emendelson
Forum All-Star
Posts: 1706
Joined: Tue Oct 14, 2008 12:12 am

Re: Copying pictures

Post by emendelson »

Hello again!

Unfortunately, the new code produces an unreadable JPEG file when run with the ExamplePicture.pct that you provided. Am I doing something wrong?

Also, I figured out why changing the name of the app to add "Show" didn't work. The first line of the on run block should read:

Code: Select all

tell application "System Events" to set myName to get name of (path to me)
And because it's likely that I'm making some foolish error in working with your code, here's the code I've got that seems to work correctly - using your earlier repeat block, not the new code in your recent message:

Code: Select all

use AppleScript version "2.4" -- Yosemite (10.10) or later
use scripting additions
use framework "Foundation" -- needed for option-key test
use framework "AppKit" -- needed for option-key test

-- based entirely on code and solutions by mabam
-- https://www.emaculation.com/forum/viewtopic.php?f=20&t=11314

-- to show image preview, either change next to true or
-- add "show" to the name of the app (as in "ConvertClipboardPICT Show")
property showImage : false

on run {}
	tell application "System Events" to set myName to get name of (path to me)
	
	if item 1 of item 1 of (clipboard info) as string is not "picture" then
		activate
		display dialog "No PICT data on the clipboard." buttons {"OK"} giving up after 5 with title myName
		error number -128
	end if
	
	-- next two lines get permissions settled at the start
	tell application "Finder" to count windows
	tell application "System Events" to count windows
	
	-- next try block gets the permissions dialog before anything else
	try
		do shell script "ls" & space & "~/Documents/clipboardConvFile.*"
	end try
	
	if myName contains "Show" then set showImage to true
	if (myName contains "Key" or myName contains "Option") then
		if (((current application's NSEvent's modifierFlags()) div 524288) mod 2) > 0 then -- 524288 = current application's NSAlternateKeyMask
			set showImage to true
		end if
	end if
	
	set myPath to POSIX path of (path to me)
	set helpers to myPath & "Contents/Resources/Helpers/"
	set dearkPath to quoted form of (helpers & "deark")
	set impbcopyPath to quoted form of (helpers & "impbcopy")
	
	set pictHeader to «data PICT0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000»
	
	try
		set clipFile to POSIX path of (path to documents folder as text) & "clipboardConvFile.pct"
		set theOpenedFile to open for access clipFile with write permission
		set eof of theOpenedFile to 0 -- Clear file content
		write pictHeader to theOpenedFile starting at eof
		write (the clipboard as picture) to theOpenedFile
		close access theOpenedFile
	on error err
		try
			close access theOpenedFile
		end try
		activate
		display dialog err
		error number -128
	end try
	
	try
		
		set sourceExtension to "pct"
		repeat
			set dearkResponse to paragraph -1 of (do shell script dearkPath & " -l -maxfiles 1 -opt pict:decodeqt ~/Documents/clipboardConvFile." & sourceExtension)
			if dearkResponse is "No files found to extract!" then
				exit repeat
			else
				set destExtension to word -1 of dearkResponse
			end if
			do shell script dearkPath & " -opt pict:decodeqt ~/Documents/clipboardConvFile." & sourceExtension & " -t ~/Documents/clipboardConvFile." & destExtension
			set sourceExtension to destExtension
		end repeat
		
	on error err
		if err contains "permission error" then
			activate
			display dialog "The converter program was unable to convert the image." buttons ("OK") giving up after 5 with title myName
			try
				do shell script "rm -f" & space & "~/Documents/clipboardConvFile.*"
			end try
			error number -128
		else
			activate
			display dialog "Deark error:" & return & return & err
		end if
	end try
	
	try
		if destExtension is in {"png", "tif", "jpg", "gif", "bmp"} then
			if destExtension is "png" then
				set imgFormat to "PNGf"
			else if destExtension is "tif" then
				set imgFormat to "TIFF"
			else if destExtension is "jpg" then
				set imgFormat to "JPEG"
			else if destExtension is "gif" then
				set imgFormat to "GIFf"
			else if destExtension is "bmp" then
				set imgFormat to "BMPf"
			end if
			set the clipboard to {picture:(read (POSIX path of (path to documents folder as text) & "clipboardConvFile." & destExtension) as imgFormat)}
		else
			do shell script impbcopyPath & space & "~/Documents/clipboardConvFile." & destExtension -- Copies the image to the clipboard as TIFF.
			set the clipboard to (the clipboard as «class PNGf») -- Copies a compressed PNG version of the image to the clipboard.
		end if
	on error err
		set trashDialog to ""
		try
			set trashDialog to return & return & "Move the converted image file out of the trash if needed."
			tell application "Finder" to move file ((path to home folder as text) & "clipboardConvFile." & destExtension) as text to trash
		on error
			set trashDialog to ""
		end try
		activate
		display dialog "Could not copy the converted image to the clipboard." & trashDialog & return & return & err buttons {"OK"} giving up after 5 with title myName
		try
			do shell script "rm -f" & space & "~/Documents/clipboardConvFile.*"
		end try
	end try
	
	if showImage is true then
		set tempFile to "~/Documents/clipboardConvFile." & destExtension
		activate
		do shell script "/usr/bin/qlmanage -p" & space & tempFile & space & "> /dev/null 2>&1 &"
		
		set counter to 0
		repeat until counter is 5
			delay 0.25
			set counter to counter + 0.25
			tell application "System Events"
				if (name of every process) does not contain "qlmanage" then
					exit repeat
				end if
			end tell
		end repeat
		if counter is 5 then
			tell application "qlmanage" to quit
		end if
		
	end if
	try
		do shell script "rm -f" & space & "~/Documents/clipboardConvFile.*"
	end try
	
end run
emendelson
Forum All-Star
Posts: 1706
Joined: Tue Oct 14, 2008 12:12 am

Re: Copying pictures

Post by emendelson »

Now that we have a registration code for GIFConverter (see the MiniVMac forum), it's possible to write a script that runs in SheepShaver and saves the image in the clipboard to a PNG file on the SheepShaver desktop. Here's one that seems to work. I can't figure out the GIFConverter scripting routine that would let me save the file directly to the Unix folder without an obscure prompt, so saving the SheepShaver desktop seemed most reliable. It should be easy to extend the script to move the PNG file to the Unix folder if anyone wants to do that.

Code: Select all

on run {}
	set clipInfo to (clipboard info) as string
	if clipInfo contains "picture" then
		my convertFile()
	else
		display dialog "No image in clipboard." buttons {"OK"} giving up after 2
	end if
	error number -128
end run

on convertFile()
	set deskDir to path to desktop folder as string
	set saveImage to "FromClipboard.png"
	set saveFile to deskDir & saveImage
	tell application "Finder"
		if exists file saveFile then
			activate
			display dialog saveImage & " already exists on the desktop." & return & return & "Delete and replace?" buttons {"Yes", "No"} default button 2
			if button returned of result is "Yes" then
				delete file saveFile
			else
				error number -128
			end if
		end if
	end tell
	
	set appRunning to false
	if (list processes) contains "GIFConverter" then
		set appRunning to true
	end if
	
	tell application "GIFConverter"
		activate
		make at beginning new graphic document
		tell image 1 of graphic document 1
			paste
		end tell
		try
			close palette 1
		end try
		save graphic document 1 in file saveFile as PNG
		try
			close graphic document 1 saving no
		end try
		if appRunning is false then
			try
				quit application "GIFConverter"
			end try
		end if
	end tell
end convertFile
User avatar
mabam
Master Emulator
Posts: 497
Joined: Wed Apr 10, 2013 9:32 am

Re: Copying pictures

Post by mabam »

emendelson wrote: Sun Sep 12, 2021 12:11 am Unfortunately, the new code produces an unreadable JPEG file when run with the ExamplePicture.pct that you provided. Am I doing something wrong?

My bad. This time I missed the “-opt pict:decodeqt” part. Please try

Code: Select all

 		set destExtension to word -1 of (do shell script dearkPath & " -l -maxfiles 1 -opt pict:decodeqt ~/Documents/clipboardConvFile.pct")
		do shell script dearkPath & " -maxfiles 1 -opt pict:decodeqt ~/Documents/clipboardConvFile.pct -t ~/Documents/clipboardConvFile." & destExtension
emendelson
Forum All-Star
Posts: 1706
Joined: Tue Oct 14, 2008 12:12 am

Re: Copying pictures

Post by emendelson »

That fixed it, thank you!

I've uploaded corrected editable and run-only versions to:

http://www.columbia.edu/~em36/ConvertClipboardPICT.zip

Well done, and thank you for sorting this all out!

I've also put together an AppleScript that runs in SheepShaver and uses the old GIFConverter utility to convert the PICT in the clipboard to a PNG file on either the SheepShaver desktop or the Unix folder. We now have a registration code for GIFConverter (the author has not been heard from since 2011, so I hope this is OK) and that makes the script possible. Will post the script after some cleanup.
User avatar
mabam
Master Emulator
Posts: 497
Joined: Wed Apr 10, 2013 9:32 am

Re: Copying pictures

Post by mabam »

emendelson wrote: Mon Sep 13, 2021 2:30 am I've uploaded corrected editable and run-only versions to:

http://www.columbia.edu/~em36/ConvertClipboardPICT.zip

Well done, and thank you for sorting this all out!
Just tested it and it all works as advertised now.
I’ve sorted this out partly, the other part was all your effort. So the credit is to you as well!

I've also put together an AppleScript that runs in SheepShaver and uses the old GIFConverter utility to convert the PICT in the clipboard to a PNG file on either the SheepShaver desktop or the Unix folder. We now have a registration code for GIFConverter (the author has not been heard from since 2011, so I hope this is OK) and that makes the script possible. Will post the script after some cleanup.
I won’t test this as I’m not using your app. But it sounds like a nice little enhancement.
User avatar
Ronald P. Regensburg
Expert User
Posts: 7821
Joined: Thu Feb 09, 2006 10:24 pm
Location: Amsterdam, Netherlands

Re: Copying pictures

Post by Ronald P. Regensburg »

I would like to post your run-only version together with a readme in the BasiliskII and SheepShaver for macOS downloads topics here. Is that OK with you?
emendelson
Forum All-Star
Posts: 1706
Joined: Tue Oct 14, 2008 12:12 am

Re: Copying pictures

Post by emendelson »

Of course yes!
Post Reply