This is a script a friend has been using under OS 9 (I did not write it). He would like to finally change over and use it under OS X (10.4). I have read some things about how Excel commands are different, as well as I think some Finder commands are changed. The script is siuppodsed to take a list of file names and past them into a column in an Excel spreadsheet template and then create new names for a second column. I started to play with this and hit a wall. Can anyone help who might have had experience doing a similar changeoverf. Thanks!!
on open (fileList)
tell application "Finder"
activate
select (fileList as list)
copy
end tell
tell application "Finder"
activate
select file "2/3D Template" of folder "Apple Menu Items" of folder "System Folder" of startup disk
open selection
end tell
tell application "Microsoft Excel"
Activate
Select Range "R9C2"
Paste
end tell
tell application "Finder"
activate
copy (the number of items in (fileList as list)) to nbFiles
repeat with currentFile in fileList
get name of currentFile
set comment of currentFile to name of currentFile
end repeat
copy (the number of items in (fileList as list)) to nbFiles
copy (display dialog "Please enter image number prefix" buttons {"OK", "Cancel"} default answer "" default button "OK") to DialogResultsA
if the button returned of DialogResultsA is "OK" then
set x to (text returned of DialogResultsA)
if (text returned of DialogResultsA) is "" then
copy (display dialog "You have to enter a image number prefix." buttons {"OK"} ¬
default button "OK" with icon caution) to DialogResultsA
else
copy (display dialog "Renaming " & nbFiles & " files," & (ASCII character of 13) ¬
& "Please enter the last Imagenumber:" buttons {"OK", "Cancel"} ¬
default answer "" default button "OK") to DialogResults
if the button returned of DialogResults is "OK" then
set Imagenumber to (text returned of DialogResults)
if Imagenumber is "" then
copy (display dialog "You have to enter a image number." buttons {"OK"} ¬
default button "OK" with icon caution) to DialogResults
else
copy (text returned of DialogResults) to fileCounter
repeat with currentFile in fileList
tell application "Finder"
copy fileCounter + 1 to fileCounter
if fileCounter is less than 10 then
copy "0" & fileCounter to fc
else
copy fileCounter to fc
end if
copy (x & fc) to fileName
set name of currentFile to fileName
end tell
end repeat
end if
end if
end if
end if
end tell
tell application "Finder"
activate
select (fileList as list)
copy
select file "2/3D Template" of folder "Apple Menu Items" of folder "System Folder" of startup disk
end tell
tell application "Microsoft Excel"
Activate
Select Range "R9C1"
Paste
end tell
end open
Thanks Jacques. Your rewrite mostly works. I found you need to change the “paste” for Excel to “paste worksheet active sheet” for Excel to understand the paste, but no information from the clipboard in the first part makes its way into column B. Any ideas what the problem is; everything else works fine. The idea is to drop a group of files on the applet, which takes the names of the files, pastes them into cells in column B and then changes the names of the files and pastes those new names in column A, establishing a link between the original name and the new name.
on open (fileList)
set theseNames to {}
tell application "Finder"
repeat with currentFile in fileList
set comment of currentFile to name of currentFile
set end of theseNames to name of currentFile & return
end repeat
select fileList
tell file "2/3D Template" of folder "Bob Goldman" of folder "Projects" of folder "Documents" of startup disk to if exists then select
open selection
end tell
set the clipboard to theseNames as string
tell application "Microsoft Excel"
select cell "B9"
paste worksheet active sheet
end tell
activate
set x to ""
repeat until x is not ""
display dialog "Please enter image number prefix" default answer ""
try
set x to text returned of result as integer
end try
end repeat
set fileCounter to ""
set fileCounter to ""
repeat until fileCounter is not ""
display dialog "Renaming " & (count fileList) & " files," & return & "Please enter the last Imagenumber:" default answer ""
try
set fileCounter to text returned of result as integer
end try
end repeat
set theseNames to {}
repeat with currentFile in fileList
set fileCounter to fileCounter + 1
if fileCounter < 10 then
set fileName to (x & "0" & fileCounter) as string
else
set fileName to (x & fileCounter) as string
end if
set end of theseNames to fileName & return
tell application "Finder" to set name of currentFile to fileName
end repeat
set the clipboard to theseNames as string
tell application "Microsoft Excel"
activate
select cell "A9"
paste worksheet active sheet
end tell
end open
Thanks again. Still no go with either choice that you suggested, though I am beginning to think there may be a different issue The script just seems to skip over that section and runs fine without pasting any information into the B column. I tested the portion of the script that copies the file names as list to the clipboard and it seems to work fine, so it is the portion involved with pasting from the list, because the portion that pastes from the dialogue input into Excel works perfectly. Any insight you or others can supply is greatrly appreciated.
I found the problem! In Excel you must uncheck the preference to “Show Paste Options buttons” and “Show Insert Options buttons” under the Edit Preferences for everything to work properly. Thanks for all your assistance. My friend is very happy.