Tuesday, August 20, 2019

#1 2019-08-14 06:33:58 am

CWilcke
Member
Registered: 2012-06-14
Posts: 10

Rename Script

Hi,

I do have a File Reanming Script and do need a little help:

Script:
set imageFolder to choose folder with prompt "Pfad Bilder" without multiple selections allowed

set theSpreadsheet to choose file with prompt "Pfad Excel Liste" without multiple selections allowed


tell application "Microsoft Excel"
    open theSpreadsheet
    tell the active sheet of the active workbook
        -- 1 erste Spalte, die befuellt ist - Original / 2 zweite befuellte Spalte 2 - renamed
        set spreadsheetData to the value of the used range
    end tell
   
end tell

tell application "Finder"
    tell folder imageFolder
        repeat with aNamePair in spreadsheetData
            set the name of file (item 1 of aNamePair) to (item 2 of aNamePair)
        end repeat
    end tell
end tell

The problem is, that some files are missing and then the script stops - is there a way to tell the script if image is missing go on with the next file in Column A in the Excel sheet?

Best,
Christoph


Filed under: rename, applescript, apple

Offline

 

#2 2019-08-14 08:01:29 am

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

Re: Rename Script

I don't own Excel for tests but you may try :

Applescript:

set imageFolders to choose folder with prompt "Pfad Bilder" without multiple selections allowed
# Here imageFolders is ALWAYS a list
set theSpreadsheets to choose file with prompt "Pfad Excel Liste" without multiple selections allowed
# Here theSpreadsheets is ALWAYS a list so we must loop in it

repeat with theSpreadsheet in theSpreadsheets
   tell application "Microsoft Excel"
       open theSpreadsheet
       tell the active sheet of the active workbook
       -- 1 erste Spalte, die befuellt ist - Original / 2 zweite befuellte Spalte 2 - renamed
       set spreadsheetData to the value of the used range
       end tell
   end tell
   
   # Here imageFolders is ALWAYS a list so we must loop in it
   tell application "Finder"
       repeat with imageFolder in imageFolders
           tell folder imageFolder
               repeat with aNamePair in spreadsheetData
                   try
                       set the name of file (item 1 of aNamePair) to (item 2 of aNamePair)
                   end try
               end repeat # with aNamePair
           end tell
       end repeat # with imageFolder
   end tell
end repeat # with theSpreadsheet

Yvan KOENIG running High Sierra 10.13.6 in French (VALLAURIS, France) mercredi 14 aout 2019  16:00:26

Offline

 

#3 2019-08-14 11:41:38 pm

CWilcke
Member
Registered: 2012-06-14
Posts: 10

Re: Rename Script

Hi Yvan,

thank you - but the script does nothing after selecting the images and the Excel Sheet it just stops and does not start the renaming sad

Best,
Christoph

Offline

 

#4 2019-08-15 07:11:17 am

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

Re: Rename Script

CWilcke wrote:

Hi Yvan,

thank you - but the script does nothing after selecting the images and the Excel Sheet it just stops and does not start the renaming sad

Best,
Christoph


I don't understand how the script may select something in the document which it's asked to open.
I assumed that you deliberately dropped the instructions supposed to define the selected area.

I know how to do that in Numbers, not in Excel.

Yvan KOENIG running High Sierra 10.13.6 in French (VALLAURIS, France) jeudi 15 aout 2019  15:09:56

Offline

 

#5 2019-08-15 08:50:27 am

Nigel Garvey
Moderator
From:: Warwickshire, England
Registered: 2002-11-20
Posts: 4940

Re: Rename Script

Yvan Koenig wrote:

I don't own Excel for tests but you may try :

Applescript:

set imageFolders to choose folder with prompt "Pfad Bilder" without multiple selections allowed
# Here imageFolders is ALWAYS a list
set theSpreadsheets to choose file with prompt "Pfad Excel Liste" without multiple selections allowed
# Here theSpreadsheets is ALWAYS a list so we must loop in it


Hi Yvan.

On my machine, choose folder and choose file only return lists when used with multiple selections allowed. When this parameter's omitted, or is explicitly without, the results are straight aliases.


NG

Offline

 

#6 2019-08-15 09:12:47 am

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

Re: Rename Script

Nigel Garvey wrote:


On my machine, choose folder and choose file only return lists when used with multiple selections allowed. When this parameter's omitted, or is explicitly without, the results are straight aliases.


A few weeks ago I couldn't get a script to work and finally determined that the behavior Nigel notes was the cause. From the AppleScript Language Guide:

""choose file
Result
The selected file, as an alias. If multiple selections are allowed, returns a list containing one alias for each selected file, if any.""

"choose folder
Result
The selected directory, as an alias. If multiple selections are allowed, returns a list containing one alias for each selected directory, if any."


2018 Mac mini - macOS Mojave

Offline

 

#7 2019-08-15 11:00:41 am

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

Re: Rename Script

Oops. I must apologizes.

My eyes where tired and read "with" when it was written "without".
I assume that it's because I am not accustomed to explicitly ask "without multiple selections allowed"

You may try with :

Applescript:

set imageFolder to choose folder with prompt "Pfad Bilder"

set theSpreadsheet to choose file with prompt "Pfad Excel Liste"

tell application "Microsoft Excel"
   open theSpreadsheet
   tell the active sheet of the active workbook
-- 1 erste Spalte, die befuellt ist - Original / 2 zweite befuellte Spalte 2 - renamed
set spreadsheetData to the value of the used range
end tell
end tell

tell application "Finder"
   tell folder imageFolder
       repeat with aNamePair in spreadsheetData
           try
               set the name of file (item 1 of aNamePair) to (item 2 of aNamePair)
           end try
       end repeat # with aNamePair
   end tell
end tell

But here again I don't see how the selected area would be defined.
Would be glad to get explanations.

Yvan KOENIG running High Sierra 10.13.6 in French (VALLAURIS, France) jeudi 15 aout 2019  18:59:53

Offline

 

Board footer

Powered by FluxBB

RSS (new topics) RSS (active topics)