Variable Name by split and calculation

Hello All!

I have 100 variables named image1, image2 all the way to image100 that originate from URLs in a one-line spreadsheet I.E. http://www.ABC.com/XYZ/GHJ/IMAGE00001.jpg

I get the filename by:
set AppleScript’s text item delimiters to “/”
Set image1 to last text item of (the spreadsheet cell)
which returns IMAGE00001.jpg only

I would like to call the variables in a shell script based on a calculation. For example

Set VARnumber to “56” --this number would be a calculation normally
set TEST to (do shell script "echo " & (“image” & VARnumber))
display dialog TEST

This returns “image56”, when I would like it to return IMAGE0056.jpg. it loses its ability to be recognized as the predefined variable.

Is there anyway around this? Brackets perhaps?

I am sure I am overlooking something - Any help would be wonderful!

Thanks All

Mark.

Model: Trashcan
Browser: Safari 537.36
Operating System: Mac OS X (10.10)

The “.jpg” component isn’t added automatically.
You must do the job by yourself.
Replace :

set TEST to (do shell script "echo " & ("image" & VARnumber))

by

set TEST to (do shell script "echo " & ("image" & VARnumber&".jpg"))

I’m just puzzled by the embedded zeroes. The posted code doesn’t insert them. Once again you must do the job by yourself.
If you want 4 digits, you may use :

set TEST to (do shell script "echo " & "image" & text 2 thru -1 of ((10000 + VARnumber) as text) & ".jpg")

If you want 5 digits use :

set TEST to (do shell script "echo " & "image" & text 2 thru -1 of ((100000 + VARnumber) as text) & ".jpg")

Yvan KOENIG running El Capitan 10.11.6 in French (VALLAURIS, France) jeudi 11 aout 2016 19:23:21

Hi Yvan,

Thanks for the reply, the IMAGE00001.jpg is the filename contained in the URL within the spreadsheet and is not that relevant really.

I probably didnt explain properly

I have variables named

image1 whose value is the last text item of “http://www.ABC.com/XYZ/GHJ/IMAGE00001.jpg
image2 whose value is the last text item of “http://www.ABC.com/XYZ/GHJ/IMAGE00002.jpg
image3 whose value is the last text item of “http://www.ABC.com/XYZ/GHJ/IMAGE00003.jpg

So…

Set VARnumber to “2” --this number would be a calculation normally
set TEST to (do shell script "echo " & (“image” & VARnumber))
display dialog TEST

The above example will return “image2” as a string. BUT not IMAGE0002.jpg as the reference to the URL.

This is because I split the variable “image1” into “image” and number

How can I get AS to give me variable value from the spreadsheet?

I hope that is clearer and thank you for your response

I want to be able to call the variable by “image” and “Xnumber” within a shell script and get the result of that variable. Not the name.

This time I don’t understand what you wrote.

If you want to build the name of a variable by calculation, it’s simple : AppleScript doesn’t allow us to create the name of a variable by any kind of calculation.

Given what I wrote above I guess that you understand that I really don’t understand what you want to achieve.
The script below show all what I may do with what you wrote.

set theURL to "http://www.ABC.com/XYZ/GHJ/IMAGE00002.jpg"
set FileName to item -2 of my decoupe(theURL, "/")
--> "IMAGE00002.jpg"
set strippedFileName to item -2 of my decoupe(theURL, {"/", "."})
--> "IMAGE00002"
set VARnumStr to (text -5 thru -1 of strippedFileName)
--> "00002"
set VARnumber to VARnumStr as integer
--> 2

set TEST to (do shell script "echo " & "image" & text 2 thru -1 of ((100000 + VARnumber) as text) & ".jpg")
--> "IMAGE00002.jpg"
display dialog TEST

#=====

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

#=====

Yvan KOENIG running El Capitan 10.11.6 in French (VALLAURIS, France) jeudi 11 aout 2016 21:04:49

Hi Mark.

As Yvan says, you can’t stick bits of variable labels together and get working variables. Possibly the best approach in your case would be to store the values in a list rather than in individual variables:

set theImages to {}

-- Assuming you're getting the items in order, starting with IMAGE00001.jpg, repeatedly:
set AppleScript's text item delimiters to "/"
set end of theImages to last text item of (the spreadsheet cell) 

-- Then, to retrieve, say, the 56th image:
set thisImage to item 56 of theImages