Sort/Archive folder action works w/MacBook, not iMac? (problem w/TIDs)

So here’s the scenario:

I am nearly brand new when it comes to AppleScript. I have a scant week of experience under my belt. I started learning because I need an automatic and self-sorting archival system for my photography/vieography business. After a few days of reading and tinkering, I was able to put a script together on my laptop (running version 10.6.8) and it works exactly as I had hoped it would. I’m very proud of this fact considering the 3 days of knowledge I had before writing it. :smiley:

The problem I’m having now is that I now can’t seem to get the same script working on my iMac workstation (I wrote it on the laptop so I could spend more time learning/working on it). At first I tried just moving the .scpt file over via USB drive and plugging in the appropriate folder paths where needed. That yielded nothing. So I am re-building the script on the iMac (10.7.4). So far everything is working except the part where I parse the filenames (and one other part that I’ll get to towards the end of this post).

The naming convention of my project folders is “year_month_day_clientName_projectName”
(Example “2012_08_03_myClient_projectName”

The script is supposed to use “_” to separate out each “chunk” of the folder name, so that I can call on item 4 of that list (the client name) to use in the sorting if block immediately after in the script. On the laptop I used to originally write the script, it works perfectly. When I try it on the iMac however, it grabs the 4th character (the 2nd “2” from “2012”) instead of grabbing the whole client name from the list of parsed chunks. I have tried everything I can think of to get it to grab the whole client name portion of the folder name, but I can only get it to grab the last character of the year. Am I doing something wrong? Does AppleScript’s text item delimiters behave differently for Lion? I could really use the help of someone more experienced.

Here’s the script in entirety:

on adding folder items to this_folder after receiving these_items
	tell application "Finder"
		set sortList to (every folder in this_folder)
		set sortItems to {}
		repeat with i in sortList
			set end of sortItems to (name of i)
		end repeat
		set newLocation to ((POSIX file "/Volumes/Drive1/Archive") as alias)
		repeat with p in sortList
			set clientArchive to (every folder in ((POSIX file "/Volumes/Drive1/Archive") as alias))
			set clientList to {}
			repeat with c in clientArchive
				set end of clientList to (name of c)
			end repeat
			set clientChoice to item 1 of (choose from list clientList with prompt "Choose for " & p)
			
			set p_Name to (name of p) as string
			set AppleScript's text item delimiters to "_" --set the delim
			set p_Parsed to every text item in p_Name
			set AppleScript's text item delimiters to "" --reset the delim
				
			if clientChoice = ("**New Client**") then
				--makes a new folder with the right client name 
				set newFolder to (make new folder at newLocation with properties {name:item 4 of p_Parsed})
				move p to newFolder
			else
				--places the folder in the chosen client archive folder
				set targetClient to (folder (clientChoice) in newLocation)
				move p to targetClient
			end if
		end repeat
	end tell
end adding folder items to

To help narrow it down as far as I can, the script IS in the appropriate folder action scripts folder in the library, and every other part of the script seems to be working. When I choose an existing client folder, the folder in question is sorted properly. When I choose to make a new folder, a new folder called “2” is made. So as near as I can tell, the only thing causing problems is the section regarding text item delimiters.

The second problem I am having is that the script seems to be copying the items I want to sort instead of moving them, despite the fact that I am using the “move” command. What gives? :confused: The whole idea of this archive system is that it will keep my entire archives off of my workstation and onto and external drive where it can’t eat up space. There’s a 2nd drive I will be setting up to mirror the 1st as added safety once I get this script working. I’m less concerned about this problem though, because in a worst-case scenario I can have the script send those extra remainders to the trash bin. (Of course I would be more pleased if I could just have it behave like it should in the first place :slight_smile: )

Any help would be greatly appreciated!

(PS: I know this is likely to be bulkier than it needs to be, considering this is the first script I have written on my own that wasn’t just some tutorial exercise. I’d gladly welcome any tips or suggestions to help condense it, but obviously my primary concern is sorting out this parsing problem)

Wait, scratch that. Well scratch part of that. I just figured out the first problem.

Turns out the iMac doesn’t like it when I reset the delimiters that soon? And the way I was referencing the 4th part of the parsed name was wrong. the corrected script looks like this:

on adding folder items to this_folder after receiving these_items
	tell application "Finder"
		set sortList to (every folder in this_folder)
		set sortItems to {}
		repeat with i in sortList
			set end of sortItems to (name of i)
		end repeat
		set newLocation to ((POSIX file "/Volumes/Drive1/Archive") as alias)
		repeat with p in sortList
			set clientArchive to (every folder in ((POSIX file "/Volumes/Drive1/Archive") as alias))
			set clientList to {}
			repeat with c in clientArchive
				set end of clientList to (name of c)
			end repeat
			set clientChoice to item 1 of (choose from list clientList with prompt "Choose for " & p) 


			set p_Name to (name of p) as string
			set AppleScript's text item delimiters to "_" --set the delim
			set p_Parsed to every text item in p_Name
			
			if clientChoice = ("_MAKE NEW FOLDER_") then	
				set newFolder to (make new folder at newLocation with properties {name:text item 4 of p_Parsed})
				move p to newFolder		
			else
				set targetClient to (folder (clientChoice) in newLocation)
				move p to targetClient
			end if
		end repeat
		set AppleScript's text item delimiters to "" --reset the delim
	end tell
end adding folder items to

note the moving of (set AppleScript’s text item delimiters to “”) to the end of the whole script and the change from {name:item 4 of p_Parsed} to {name:text item 4 of p_Parsed}

The change from item 4 to text item 4 I get, but does anyone know why moving the delimiter reset to the end works instead of right after it gets used? (or more precisely why it works right after on Snow Leopard and not on Lion?)

Still working on the “move-commands-making-copies-instead-of-just-moving-things” problem though. I’ll post a solution if I find one to that works.

Hi. Welcome to MacScripter.

I can’t see any reason, just reading the scripts, why either should work on one computer but not another, provided the value of ‘newLocation’ is the same for both. There’s nothing in the scripts which would ever allow ‘clientChoice’ to be either “MAKE NEW FOLDER” or “New Client”.

The first script’s correct in this respect, the second wrong. It should be either (as in the first script):

set AppleScript's text item delimiters to "_" --set the delim
set p_Parsed to every text item in p_Name
set AppleScript's text item delimiters to "" --reset the delim
-- blah blah blah
{name:item 4 of p_Parsed} -- The fourth item in the list p_Parsed

Or:

set AppleScript's text item delimiters to "_" --set the delim

{name:text item 4 of p_Name} -- The fourth text item in the text p_Name (not in the list p_Parsed)

set AppleScript's text item delimiters to "" --reset the delim

There must of course be at least four underscore-delimited text items in p_Name for either way to work.

That’s what happens when the Finder “moves” an item to another disk. It leaves the original in place. You’ll have to use ‘delete’ or ‘move to trash’ ” when you’re sure the copies are arriving safely at the other end, of course. :slight_smile:

I’ll look at the scripts again at more leisure to see if I can think of anything else.

Thanks for taking the time to take a look and explain!