Running Script on Connected Volume

One of the members here suggested a script that lets me label folders a specific color if the name of the folder contains matching text from a CSV file.


Works fine on my Mac.


If I try to use it for folders on our server it does not work.

I'm running the script from my Mac connected to our server.

The files are on an external mount to the server.


The pathname of the folder is similar to

/Volumes/Folder/Working Folder

The server is connected via afp and IP address afp://00.0.0.000/Folder


I'm not very good at any of this so hoping someone sees something obvious I'm missing.


Script is below.


-- prompt the user for the file containing the folder prefixes

set JobPrefixes to paragraphs of (read file (choose file with prompt "Select the Job List file" of type "public.comma-separated-values-text"))


-- iterate through the prefixes

repeat with eachJob in JobPrefixes

-- make sure we don't have a blank line

if eachJob as text ≠ "" then

tell application "Finder"

-- change the label color of folders who match the prefix

-- 0 - None

-- 1 - Orange

-- 2 - Red

-- 3 - Yellow

-- 4 - Blue

-- 5 - Purple

-- 6 - Green

-- 7 - Grey

set label index of (every folder of folder jobsFolder whose name begins with eachJob) to 7

end tell

end if

end repeat

Posted on Apr 10, 2025 11:09 AM

Reply
8 replies

Apr 10, 2025 11:32 AM in response to vondy21

It would help to know what you mean by 'does not work'.


That could be any of:


does nothing

throws an error message

changes some items, but not others

changes items in the wrong way


Assuming it throws an error message, including that message would go a long way to helping identify the cause. There are so many possible failure states, it's hard to know which one is applicable here without more context, and the error message would help hone in on the issue.


As it stands, the script can't run anyway, so there's something missing. Specifically, the line:


			set label index of (every folder of folder jobsFolder whose name begins with eachJob) to 7


Nowhere in your script is 'jobsFolder' defined, so the script is going to throw an error at this point, unless it's defined somewhere else and you didn't include the whole script in your post.


You do say:


> The pathname of the folder is similar to

> /Volumes/Folder/Working Folder


but that's not defined anywhere in the script that I can see.


Assuming that's resolved somehow, you say it's a CSV file, but there is no parsing of the text file, beyond breaking it into paragraphs. This script could only work if the lines in the text file exactly matches the folder name, which likely precludes command-separated values, unless there's only one value per line.


That's why knowing the failure state and error message is important.


Apr 10, 2025 12:26 PM in response to Camelot

If I run the script on a folder on my desktop, it finds the matching folder names from the CSV file and labels them red. If I do the same to a folder on our server it does not change the label, or Tag, to red. Does not show an error either, just doesn't work.


Now perhaps this has something to do with our server being on an older OS?


I tried screensharing the server and running the script directly from there and it did give me an error.


Can't make file (alias "Macintosh HD:User:xxxxxxx:Tags.csv") into type file.


If I run the same script on my desktop Mac, it works.


I believe it has something to do with the older Script Editor maybe? It's AppleScript 2.5.


On my desktop it's 2.8.


The CSV file looks like this:


123456

879531

165478


Just a single column.


The folder names would be like:

123456 Company Name 1

879531 Company Two


I type the Folder location into the script. (there are several sub folders in that folder)


The script ask for the CSV file and then it does its thing.


That help at all?



Apr 10, 2025 02:40 PM in response to vondy21

Too funny that it's my own script. :)


Shame the corner case of server-side files weren't considered at the time.


The error message goes a long way to clarifying what's wrong:


> Can't make file (alias "Macintosh HD:User:xxxxxxx:Tags.csv") into type file.


That means it can't find/read the Tags.csv file.


The AppleScript version is irrelevant here. That's about as plain vanilla as AppleScript gets, and there's nothing that relies on a newer version of AppleScript.


How, exactly, are you invoking this? You said you're running screen sharing to the server, and running it there? Any particular reason, vs. running it on your own machine over the network (not that I think it's critical to the issue at hand, though).


Do you only get the error message if you run the script on the server? or do you also get that if you run the script locally? Do you get any message/error when run locally?


I still don't see where JobsFolder is getting defined in the script. Is that the whole script?

Apr 11, 2025 08:56 AM in response to Camelot

Below is the exact script from you. I'm not sure about the JobsFolder part.


If I run the script on a folder on my desktop it works.


If I run the script from my desktop to a folder on our server it does not work or give me an error.


If I place the script on the sever's desktop and run the script from there to a folder on the server's desktop it gives me the "can't find/read" error. Same error if I choose a folder on the mounted drive connected to the server, running from the server.


I use screenshare because our server is a headless MacMini and I don't want to have to drag out a monitor and hook up, etc.


The curious thing is why does it error on the server but works fine on my desktop?



-- Change this line to the path where your job folders are

set jobsFolder to "Macintosh HD:Users:yourname:Desktop:"


-- prompt the user for the file containing the folder prefixes

set JobPrefixes to paragraphs of (read file (choose file with prompt "Select the Job List file" of type "public.comma-separated-values-text"))


-- iterate through the prefixes

repeat with eachJob in JobPrefixes

-- make sure we don't have a blank line

if eachJob as text ≠ "" then

tell application "Finder"

-- change the label color of folders who match the prefix

-- 0 - None

-- 1 - Orange

-- 2 - Red

-- 3 - Yellow

-- 4 - Blue

-- 5 - Purple

-- 6 - Green

-- 7 - Grey

set label index of (every folder of folder jobsFolder whose name begins with eachJob) to 7

end tell

end if

end repeat

Apr 11, 2025 11:56 AM in response to vondy21

> Below is the exact script from you. I'm not sure about the JobsFolder part.


Ahh, then I'm glad to know I'm not going crazy. The script you posted in the beginning is NOT the same as this script (or the one I wrote way back when). In your earlier post you missed this line:


-- Change this line to the path where your job folders are
set jobsFolder to "Macintosh HD:Users:yourname:Desktop:"


Which is kind of important, and is the exact thing I was saying earlier.


Now we have that straight we have a better chance of working this out.


I assume that you're changing this line when you run the script, since it's kind of locked to a specific folder. The big question is what you're changing it to.


When you run it on your machine, and are trying to change files on the server, it should look something like:


-- Change this line to the path where your job folders are
set jobsFolder to "Server Volume:Folder:"


Where 'Server Volume' is the name of the server as seen on your Desktop, and 'Folder' is a folder on that server.


If you're running the script on the server itself, then the path will need to reflect where the files are. They're not likely to be in some user's home directory, although that may be the case, depending on how you've configured file services on the server.


Apr 18, 2025 08:22 AM in response to Camelot

Hey, didn't get a notification about your post but it works!


Appreciate that.


At least it worked on my small test folder on the connected volume.


When I run it on the folder with 2,000+ folders in it, it locks up my finder.


I think there are just too many folders.


Tried again to run it on there server itself but I get that same

"Can't make file (alias "Macintosh HD:User:xxxxxxx:Tags.csv") into type file"

error.


Apr 21, 2025 11:16 AM in response to vondy21

> When I run it on the folder with 2,000+ folders in it, it locks up my finder.


Yeah, the Finder really chokes when handed large numbers of files to deal with, especially on a remote volume. Kind of odd, really, since you'd think this is exactly what the Finder is supposed to do.


There is an alternative model I have that's a lot faster, that uses a shell script to dive under the hood, but it involves copying the label settings from an existing file (I've never managed to work out the right syntax for setting arbitrary labels ad hoc, so it's much easier to just copy what some other file has :) )


The good thing is that this model allows for multiple labels/tags (e.g. a file could be Blue and Green), which is something my original script never handled. Let me know if you want to give it a try.

This thread has been closed by the system or the community team. You may vote for any posts you find helpful, or search the Community for additional answers.

Running Script on Connected Volume

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