Apple Intelligence is now available on iPhone, iPad, and Mac!

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

Excel spreadsheet has 2 parts of directory path

I am struggling with finding out what is missing in my script. I have a spreadsheet that lists beginning folder in column 1 and the next folder down in column 2. The spreadsheet can have 50 or 60 rows.

So far my script will pull the info from "A2:C" using a variable for the number of rows found.


I need find the folder listed in the spreadsheet and copy it to a new location.

I am not getting around an error where Finder can't set target to.....

I've tried set as string, set as alias, set as nothing. What am I missing?


tell application "Microsoft Excel"

tell active sheet

tell used range

set rc to count of rows

end tell

set theList to get value of range ("A2:C" & rc) as list


logtheList

repeat with theItem in theList

end repeat

end tell

end tell

--repeat with thisItem in theList

tell application "Finder"


-- set numb to 1

set target to (files_source & theItem & ":" as string)


logtarget


--try


-- copy target to files_dest


--end try

end tell

MacBook Pro (17-inch Early 2011), OS X Mavericks (10.9.2)

Posted on Aug 21, 2018 1:21 PM

Reply
Question marked as Top-ranking reply

Posted on Aug 22, 2018 12:19 PM

Camelot, thank you for helping identify the targets in the list. I know I was missing that also. I am including the complete error. I originally was trying the add : as column B since I had trouble separating the 2 columns when defining the path. Using your logic, I remove the silly bandaid and changed it to only read the 2 columns. I am pasting the entire script after the error. I know the problem is the extra "." that somehow gets in the string. I just do not know where it comes from. You are right, I am commenting out some lines to try and decipher where this error is coming from and to not take the action the script is intended to take since this server is not local and having it copy these jobs is not needed to get the rest correct. It looks as though target resolves well but finder does not like it.


tell application "Microsoft Excel"


count every row of used range of active sheet


get value of range "A2:B4" of active sheet

end tell

tell application "Finder"


set target to "FileData:GPS_VAN_Jobs:Amazon Fresh:5000234-01"

Result:

error "Finder got an error: Can’t set target to \"FileData:GPS_VAN_Jobs:Amazon Fresh:5000234-01:\"." number -10006 fromtarget


set files_source to "FileData:GPS_VAN_Jobs:" as string

--set files_dest to "Preflight:Archive:" as alias

tell application "Microsoft Excel"

tell active sheet

tell used range

set rc to count of rows

end tell

set theList to get value of range ("A2:B" & rc) as list

end tell

end tell

--repeat with thisItem in theList

tell application "Finder"

repeat with theItem in theList

set colA to item 1 of theItem

set colB to item 2 of theItem

set target to (files_source & colA & ":" & colB) as text


logtarget


--try


-- copy target to files_dest


--end try

end repeat

end tell

6 replies
Question marked as Top-ranking reply

Aug 22, 2018 12:19 PM in response to Camelot

Camelot, thank you for helping identify the targets in the list. I know I was missing that also. I am including the complete error. I originally was trying the add : as column B since I had trouble separating the 2 columns when defining the path. Using your logic, I remove the silly bandaid and changed it to only read the 2 columns. I am pasting the entire script after the error. I know the problem is the extra "." that somehow gets in the string. I just do not know where it comes from. You are right, I am commenting out some lines to try and decipher where this error is coming from and to not take the action the script is intended to take since this server is not local and having it copy these jobs is not needed to get the rest correct. It looks as though target resolves well but finder does not like it.


tell application "Microsoft Excel"


count every row of used range of active sheet


get value of range "A2:B4" of active sheet

end tell

tell application "Finder"


set target to "FileData:GPS_VAN_Jobs:Amazon Fresh:5000234-01"

Result:

error "Finder got an error: Can’t set target to \"FileData:GPS_VAN_Jobs:Amazon Fresh:5000234-01:\"." number -10006 fromtarget


set files_source to "FileData:GPS_VAN_Jobs:" as string

--set files_dest to "Preflight:Archive:" as alias

tell application "Microsoft Excel"

tell active sheet

tell used range

set rc to count of rows

end tell

set theList to get value of range ("A2:B" & rc) as list

end tell

end tell

--repeat with thisItem in theList

tell application "Finder"

repeat with theItem in theList

set colA to item 1 of theItem

set colB to item 2 of theItem

set target to (files_source & colA & ":" & colB) as text


logtarget


--try


-- copy target to files_dest


--end try

end repeat

end tell

Aug 23, 2018 6:14 AM in response to E.D.S.

It would help if you posted the actual error message you're getting. There's a surprising amount of detail in there, if you know how to read it. At the very least it would identify what data your script is trying to work with.

It would also help to show your source data so we can understand what you're working with.


From what I can see, you're trying to build a directory path. However, nowhere in your script is files_source defined. Either that's an error in your script, or there's more to your script that you haven't posted.


Other than that, your structure doesn't make sense - presumably since you've been editing and commenting/uncommenting parts to try to get different things to work.


Most notably, your line:


set target to (files_source & theItem & ":" as string)

is doomed to fail, not only because files_source is undefined (see above), but so is theItem since that's your list iterator that is currently empty:


repeat with theItemintheList

end repeat

Also, and a major contributor to your problem, may be the way Excel returns the value of a range.


Assuming that you have 50 rows in your database, the command:


set theList to get valueofrange ("A2:C" & rc) as list

will return a list of 40 items - one per row - where each item is itself a list of three values corresponding to the three columns in the range.


To extract the specific values from this, you need another level of indirection.


Finally - and this is the kicker - target is a reserved keyword in the Finder's dictionary (it's a property of a window), so you're running into dictionary term conflicts.


Here's a reworked version of your script that might help get you straight:


tell application "Microsoft Excel"

tell active sheet

tell used range

set rc to count of rows

end tell

set theList to get value of range ("A2:C" & rc) as list


logtheList

end tell

end tell

tell application "Finder"

repeat with theItem in theList

set colA to item 1 of theItem

set colB to item 2 of theItem

set colC to item 3 of theItem

set target to (colA & ":" & colB & ":" as text)


logtarget


-- other commands go here

end repeat

end tell

Aug 23, 2018 6:14 AM in response to rccharles

Use the log statement for debugging. I put a log statement after about every assignment 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.


    Author: rccharles
    
    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

 *)


on run
    -- Write a message into the event log.
    log "  --- Starting on " & ((current date) as string) & " --- "
    --  debug lines
    set desktopPath to (path to desktop) as string
    log "desktopPath = " & desktopPath
end run

Excel spreadsheet has 2 parts of directory path

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