Script Help Please - Selective Image Removal

Hi All,

Would anyone with script expertise be willing to help with a script I’m trying to write?

Its purpose is to automate removing all photos from a listing (and ideally, multiple selected listings all at once) EXCEPT for the first image.

I started writing it by looking at the functioning ‘Remove first image of selected listings’ in the AppleScriptExamples sample scripts that I downloaded from this site, then making changes. Within the Mac’s Script Editor app it compiles without any errors shown. But when I paste it into the Script Editor window within GarageSale and press Run, I get an error: SyntaxError: Unexpected identifier ‘application’ – I have no previous experience writing scripts so I am a bit lost as to how to correct it.

Here is the script that I have so far:

tell application “GarageSale”

repeat with theListing in (get selected ebay listings)

    -- Check if the listing has more than one image

    if (count of listing images of theListing) > 1 then

        -- Get the list of images for the current listing

        set theImages to listing images of theListing            

        -- Start removing images from the second one onwards

        repeat with i from 2 to (count of theImages)

            set imageToRemove to item i of theImages

            tell theListing

                -- Remove the image

                remove listing image imageToRemove

            end tell

        end repeat

    end if

end repeat

end tell

For me it sounds you have inserted Apple Script into the GarageSale Javascript Editor. This won’t work.

Instead, simply use Apple’s Script Editor application and use the run (play) button there to run the script.

Thanks, Kristian–I just tried that in Apple’s Script Editor and got the following error: error “GarageSale got an error: Some parameter is missing for remove listing image.” number -1701

So I am thinking there is something incorrect with the way I have attempted to write the script, but I don’t know what’s wrong because it compiled okay and only shows the error when trying to run the script.

This works fine for me (in Apple’s Script Editor):

tell application "GarageSale"

repeat with theListing in (get selected ebay listings)
	-- Check if the listing has more than one image
	
	if (count of listing images of theListing) > 1 then
		-- Get the list of images for the current listing
		
		set theImages to listing images of theListing
		-- Start removing images from the second one onwards
		
		repeat with i from 2 to (count of theImages)
			set imageToRemove to item i of theImages
			tell theListing
				-- Remove the image
				
				remove listing image image imageToRemove
				
			end tell
		end repeat
	end if
end repeat
end tell

Thanks Kristian–I copied this code you posted and it is working perfectly for me. I appreciate everything you and the GarageSale team do–thanks again for your help!

Awesome, feel free to post your script in the GarageSale Scripts category. It could also be helpful for others!

I save all scripts to a dedicated folder on one of my hard drives.

This main folder is divided into subfolders according to the application the scripts automate.

I save projects as a AppleScript and as application. Frequently used applications get placed on the edge of one of my flatscreens so I can simply move my mouse off the edge of GS and double click it to perform a task.

You should run the AppleScripts as apps as opposed to running them in the Script Editor all the time.

You could also a product similar to the application Dock-It, which allows you to put additional docks around the edges of your desktop screen, which reveal their contents upon a mouse hover.

Opened by mistake so I deleted post

This topic was automatically closed 10 days after the last reply. New replies are no longer allowed.