You can make a difference in the Apple Support Community!

When you sign up with your Apple Account, you can provide valuable feedback to other community members by upvoting helpful replies and User Tips.

Looks like no one’s replied in a while. To start the conversation again, simply ask a new question.

Download bulk pictures from a list of urls in excel file and then rename the pictures

Hi Everyone,


I really hope someone can help me. I am very new to this Apple and its scripting. What I need to do is very close to this thread but I can not understand how to change.


https://discussions.apple.com/thread/7603407?answerId=30384806022#30384806022


The below script from Camelot is exactly what I need however I need to make a few changes


  1. my rows are "A1:A29404" for image new / code name
  2. my rows are "B1:B29404" for URLs
  3. I don't use Yosemite, I use Latest Catalina, I don't know which version AppleScript I have
  4. My folder path would be "desktop/ImagesDownload"
  5. And I do not use Numbers, I use Excel
  6. where do I put my file name, or how does this work? will this script ask me to open the file and then run the script? How do I save this script as an app?


Script from Camelot

---------------------


use AppleScriptversion "2.4" -- Yosemite (10.10) or later

use scripting additions


tell application "Numbers"

set filenames to value of every cell of range "A1:A8" of table 1 of sheet 1 of document 1

set URLs to value of every cell of range "B1:B8" of table 1 of sheet 1 of document 1

end tell


repeat with i from 1 to count URLs

if (item i of filenames is not missing value) and (item i of URLs is not missing value) then

set thisFname to quoted form of (POSIX path of ((path to desktop) as text) & item i of filenames)

set thisUrl to quoted form of item i of URLs


set status to (do shell script "echo curl -s -o " & thisFname & space & thisUrl)


end if

end repeat

---------------------


Many thanks in advance.

Posted on Nov 26, 2021 2:35 AM

Reply

Similar questions

8 replies

Nov 26, 2021 4:21 PM in response to Briggsbridget


  1. my rows are "A1:A29404" for image new / code name
  2. my rows are "B1:B29404" for URLs


So open your file in excel and copy & paste these values to a number sheet. at this beginner level, you will not notice the difference.


  1. I don't use Yosemite, I use Latest Catalina, I don't know which version AppleScript I have


Your good. Catalina comes after Yosemite. This is just checking if you have the correct level of script support. You will because Catalina comes after Yosemite


  1. My folder path would be "desktop/ImagesDownload"


To change; try:

set status to (do shell script "cd ~/Desktop/ImagesDownload; echo curl -s -o " & thisFname & space & thisUrl)


the cd is change directory. move to the correct directory.


This is just for testing; to run you need to remove echo.



  1. And I do not use Numbers, I use Excel

It's going to be more work converting to Excel. Since you only using columns a & b, you might as well use numbers. A spreadsheet is a spreadsheet.

  1. where do I put my file name, or how does this work? will this script ask me to open the file and then run the script? How do I save this script as an app?


The script works on the currently open numbers spreadsheet.


The file names are in column A. ... right.


Nov 26, 2021 4:22 PM in response to rccharles

how to create an applescript app.


The first thing that you need to do is to make the text into an AppleScript program.
Start the Script Editor
/Applications/Utilities/Script Editor.app
Copy the script text to the Script editor.
Save the text to a file as an application and do not check any of the boxes below.

If you want access to the script from your Script Menu, move the script (the saved script application file) to your ~/Library/Scripts folder. You can also drag it to your Dock or make an alias for it on the Desktop.

To debug, run the script within the Applescript Editor. Click on the event log tab at the bottom of the window. Click on the run icon. The results from the log statement will be shown at the bottom of the screen.

------------------------- beginning of applescript --------------------
(*
Here is how to create an Applescript Application.

https://discussions.apple.com/thread/3033221?tstart=30

*)
on run
    -- Write a message into the event log.
    -- To see, run this applescript in Sript Editor. Click on Event Log tab at bottom of screen.
    -- Click run.
    log "  --- Starting on " & ((current date) as string) & " --- "
    set fromApp to "Safari"
    set toApp to "TextEdit"
    --- We have arrived.
    say "we are beginning now."
    -- Start your application
    tell application fromApp
        activate
    end tell
    delay 1
    say "copy data to clipboard"
    tell application "System Events"
        tell process fromApp
            keystroke "c" using command down
            delay 2
        end tell
    end tell
    -- Start your application
    tell application toApp
        activate
    end tell
    delay 5
    tell application "System Events"
        tell process fromApp
            --  open file menu
            keystroke return
            keystroke return
            keystroke return
            keystroke "v" using command down
        end tell
    end tell
    say "good news, We are done."
end run

--------------------------------- end of the applescript program -------------------

Nov 27, 2021 1:53 AM in response to rccharles

Thank you rccharles for your reply, an excellent explanation and I am sure I could make this work, however, I just have another problem, since I was using Excel, I never needed the Numbers.app. I do not have the Numbers.app and when I try to download it from the Mac App store, it is saying my system is not compatible. It seems to download for newer versions of OS. Where can I get the official old Number app from? Mac's website is the very old version listed and not the latest version for Catalina?


Once again thank you.

Nov 30, 2021 12:06 AM in response to Briggsbridget

I converted the script to use excel. You will need to adjust my short user id from mac to your short user id.


Shows log statement.

 

 It is easier to diagnose problems with debug information. I suggest adding log statements to your script to see what is going on. Here is an example.

For testing, run in the Script Editor.

1) Click on the Event Log tab to see the output from the log statement

2) Click on Run



(* 

https://discussions.apple.com/thread/253404122

To give you the context of the field names, the excel table contianed information 
          A                       B                 
imageName      	imageURL     
*)

-- Write a message into the event log.
set commonMessage to "  --- Starting on " & ((current date) as string) & " --- "
log commonMessage & return

-- The filename of the excel sheet containing the name and email address, etc.
set fileName to "/Users/mac/Documents/imageList.xlsx"
log "fileName is " & fileName

tell application "Microsoft Excel"
	activate
	open fileName
	tell active sheet
		tell used range
			set rowCount to count of rows
		end tell
		log "rowCount is " & rowCount
		--set theInputFolder to (choose folder with prompt "Folder you wish to copy the .dng and .nef files")
		set runAwayCount to 1
		set runAwayMax to 51
		repeat with i from 1 to (runAwayMax - 1) -- rowCount
			log "Processing record " & i
			if runAwayCount > runAwayMax then
				log " running away "
				-- this is DIY. You need to fix.
				display dialog "How many more times do you want to continue?" default answer 50
			end if
			
			set runAwayCount to runAwayCount + 1
			
			set imageName to get value of range ("A" & i)
			log "imageName is " & imageName
			
			
			-- are we done yet? ends with a blank cell
			if (count of imageName) is 0 then
				exit repeat
			end if
			
			set imageURL to get value of range ("B" & i)
			log "imageURL is " & imageURL
			
			-- set toUnix to "cd ~/Desktop/ImagesDownload; echo curl -s -o " & imageName & space & imageURL
			set toUnix to "cd ~/Desktop/ImagesDownload; curl -s -o " & imageName & space & imageURL
			log "toUnix is " & toUnix
			
			set status to (do shell script toUnix)
			log "status is " & status
			
			set theCommand to "ls -l  /Users/mac/Desktop/ImagesDownload/" & imageName
			log "theCommand is " & theCommand
			try
				set fromUnix to do shell script theCommand
			on error
				log "failure"
			end try
			
			try
				log "fromUnix is " & fromUnix
			on error
				log "failure #2"
			end try
			
		end repeat
	end tell -- active sheet
	close workbooks
	quit
end tell -- excel  


Dec 15, 2021 9:56 PM in response to Briggsbridget

Clean up.


(* 


https://discussions.apple.com/thread/253404122




To give you the context of the field names, the excel table contianed information 
          A                       B                 
imageName      	imageURL  
   
Red_menace says
    Depending on what the script is doing, pressing command-period will cancel it.  
	https://support.apple.com/en-il/guide/script-editor/scrptedshtcut/mac


*)
on run
	
	-- Write a message into the event log.
	set commonMessage to "  --- Starting on " & ((current date) as string) & " --- "
	log commonMessage & return
	
	-- echo $USER
	set toUnix to "echo $USER"
	log "toUnix is " & toUnix
	
	try
		set currentUser to do shell script toUnix
		log "currentUser is " & currentUser
	on error errMsg number n
		log "echo $USER error..." & errMsg & " with number " & n
		exit repeat -- generates an error which get us out of here.
	end try
	
	
	-- The filename of the excel sheet containing the name and email address, etc.
	set fileName to "/Users/" & currentUser & "/Documents/imageList.xlsx"
	log "fileName is " & fileName
	
	
	tell application "Microsoft Excel"
		activate
		open fileName
		tell active sheet
			tell used range
				set rowCount to count of rows
			end tell
			log "rowCount is " & rowCount
			set runAwayMax to 50
			set i to 1
			repeat while i > 0
				
				log return & "Processing record " & i
				if i is runAwayMax then
					log " running away "
					-- The idea here is the user can control the running of this script
					display dialog "How many more times do you want to continue? End? Click cancel." default answer 100
					set moreRunning to text returned of result
					log "moreRunning is " & moreRunning
					set runAwayMax to i + moreRunning
					log "runAwayMax is " & runAwayMax
				end if
				
				set imageName to get value of range ("A" & i)
				log "imageName is " & imageName
				
				-- are we done yet? ends with a blank cell
				if (count of imageName) is 0 then
					log "Goodbye."
					exit repeat
				end if
				
				set imageURL to get value of range ("B" & i)
				log "imageURL is " & imageURL
				
				set toUnix to "cd ~/Desktop/ImagesDownload; curl -s -o " & imageName & space & imageURL
				log "toUnix is " & toUnix
				try
					set status to (do shell script toUnix)
				on error errMsg number n
					log "echo $USER error..." & errMsg & " with number " & n
				end try
				log "status is " & status
				
				set theCommand to "ls -l  /Users/" & currentUser & "/Desktop/ImagesDownload/" & imageName
				log "theCommand is " & theCommand
				try
					set fromUnix to do shell script theCommand
				on error errMsg number n
					log "==> Unix found an error 🙃. " & errMsg & " with number " & n
				end try
				
				try
					log "fromUnix is " & fromUnix
				on error errMsg number n
					log "==> Unix found another place to error 🙃. " & errMsg & " with number " & n
				end try
				
				-- increment
				set i to i + 1
				
			end repeat
			
		end tell -- active sheet
		close workbooks
		quit
	end tell -- excel  
	
	
end run

Download bulk pictures from a list of urls in excel file and then rename the pictures

Welcome to Apple Support Community
A forum where Apple customers help each other with their products. Get started with your Apple Account.