need to add another exception to file list

I have this working but the line in bold doesn’t work how can I add this rule to the current script.

Basically of the file name begins with 5 or starts MJC it must leave the file where it is/

Many Thanks

Matt

property type_list : {"TIFF", "JPEG", "PNGf", "PICT"}
property extension_list : {"tif", "tiff", "jpg", "jpeg", "png", "pict", "psd"}

set tFolder to ("Hal 9000:Users:matthew:Desktop:HotFolder") as string

tell application "Finder"
	repeat with tFile in (get document files of folder tFolder whose name extension is in the extension_list

[i]and whose name does not start with “50” or “MJC”)[/i]

set nLayers to my getNumOfLayers(tFile as string)
		if nLayers < 5 then
			move tFile to the folder "Hal 9000:Users:matthew:Pictures:HotFolder2do" -- move to subFolder A
		else
			move tFile to the folder "Hal 9000:Users:matthew:Pictures:HotFolderDone"
		end if
	end repeat
end tell

on getNumOfLayers(f)
	((do shell script "/usr/bin/mdls -name kMDItemLayerNames " & (quoted form of POSIX path of f) & " | /usr/bin/wc -l ") as integer) - 2
end getNumOfLayers

You’re pretty close


(get document files of folder tFolder whose name extension is in extension_list and (name does not start with "50" or name does not start with"MJC")) 

This is how it looks now, It still pushes the exceptions into the folders when the behaviour I would expect is to stay where it is.

Any idea as to why it still moves into the folders?

Matt

property type_list : {"TIFF", "JPEG", "PNGf", "PICT"}
property extension_list : {"tif", "tiff", "jpg", "jpeg", "png", "pict", "psd"}

set tFolder to ("Hal 9000:Users:matthew:Desktop:HotFolder") as string

tell application "Finder"
	repeat with tFile in (get document files of folder tFolder whose name extension is in extension_list and (name does not start with "50" or name does not start with "MJC"))
		set nLayers to my getNumOfLayers(tFile as string)
		if nLayers < 5 then
			move tFile to the folder "Hal 9000:Users:matthew:Pictures:HotFolder2do" -- move to subFolder A
		else
			move tFile to the folder "Hal 9000:Users:matthew:Pictures:HotFolderDone"
		end if
	end repeat
end tell

on getNumOfLayers(f)
	((do shell script "/usr/bin/mdls -name kMDItemLayerNames " & (quoted form of POSIX path of f) & " | /usr/bin/wc -l ") as integer) - 2
end getNumOfLayers

Your test was wrong.


property type_list : {"TIFF", "JPEG", "PNGf", "PICT"}
property extension_list : {"tif", "tiff", "jpg", "jpeg", "png", "pict", "psd"}

set tFolder to ("Hal 9000:Users:matthew:Desktop:HotFolder") as string

tell application "Finder"
	repeat with tFile in (get document files of folder tFolder whose name extension is in extension_list and (name does not start with "50" and name does not start with "MJC"))
		set nLayers to my getNumOfLayers(tFile as string)
		if nLayers < 5 then
			move tFile to the folder "Hal 9000:Users:matthew:Pictures:HotFolder2do" -- move to subFolder A
		else
			move tFile to the folder "Hal 9000:Users:matthew:Pictures:HotFolderDone"
		end if
	end repeat
end tell

on getNumOfLayers(f)
	((do shell script "/usr/bin/mdls -name kMDItemLayerNames " & (quoted form of POSIX path of f) & " | /usr/bin/wc -l ") as integer) - 2
end getNumOfLayers

The original one was accepting the files whose name was not starting with “50”
plus
those whose name was not starting with “MJC”
so it accepted every files.

The edited one accept only (files whose name don’t start by “50”) whose name don’t start by “MJC”.

Yvan KOENIG (VALLAURIS, France) mercredi 29 février 2012 15:01:31

Yes… and no…

Strange behaviour with this one.
I’m running the LaunchD watchfile so that when the files arrive they get moved about. If there is one labeled MJC… or 50… Nothing moves.

If you manually run the applescript everything moves except the MJC… or the 50… as expected.

I am attaching it to a previous script. as posted herehttp://macscripter.net/viewtopic.php?id=38177

property csvAlias : alias ((path to desktop as text) & "SourceFiles:ean2sku.csv") --path to your csv-File as alias
property csvDelimiter : "," --delimiter used by your csv-File


tell application "Finder"
	set this_folder to folder "HotFolder" as alias
	set itemList to every file in this_folder
end tell
try
	set TID to AppleScript's text item delimiters
	
	repeat with i from 1 to count of itemList
		set newFile to item i of itemList
		
		
		tell application "System Events" to set {fSuffix, fName} to {(name extension of disk item (newFile as text)), (displayed name of disk item (newFile as text))}
		
		if fSuffix is not "" then set fSuffix to "." & fSuffix
		set fName to my stripSuffix(fSuffix, fName)
		set tmpName to (text 1 thru 13 of fName)
		
		set csvText to read csvAlias
		
		if csvText contains tmpName then
			set AppleScript's text item delimiters to tmpName & csvDelimiter
			
			set newListName to (text 1 thru -1 of (paragraph 1 of (text item 2 of csvText)))
			
			if (count of fName) is greater than 13 then
				set newName to newListName & (text 14 thru -1 of fName) & fSuffix
			else
				set newName to newListName & fSuffix
			end if
			my renameFile(this_folder, fName & fSuffix, newName)
			
		end if
	end repeat
	
	set AppleScript's text item delimiters to TID
	
on error
	display dialog "Could not rename: " & fName giving up after 3
end try


on stripSuffix(fSuffix, fName)
	if fName contains fSuffix then
		set AppleScript's text item delimiters to fSuffix
		return (text item 1 of fName)
	end if
end stripSuffix

on renameFile(this_folder, origName, newName)
	set sourcePath to quoted form of POSIX path of ((this_folder as text) & origName)
	set targetPath to quoted form of POSIX path of ((this_folder as text) & newName)
	do shell script "mv -f " & sourcePath & space & targetPath
end renameFile


-- This areas then moves the files to the relevant folders

property type_list : {"TIFF", "JPEG", "PNGf", "PICT"}
property extension_list : {"tif", "tiff", "jpg", "jpeg", "png", "pict", "psd"}


set tFolder to ("Hal 9000:Users:matthew:Desktop:HotFolder") as string

tell application "Finder"
	repeat with tFile in (get document files of folder tFolder whose name extension is in extension_list and (name does not start with "50" and name does not start with "MJC"))
		set nLayers to my getNumOfLayers(tFile as string)
		if nLayers < 5 then
			move tFile to the folder "Hal 9000:Users:matthew:Pictures:HotFolder2do" -- move to subFolder A
		else
			move tFile to the folder "Hal 9000:Users:matthew:Pictures:HotFolderDone"
		end if
	end repeat
end tell

on getNumOfLayers(f)
	((do shell script "/usr/bin/mdls -name kMDItemLayerNames " & (quoted form of POSIX path of f) & " | /usr/bin/wc -l ") as integer) - 2
end getNumOfLayers

I was unable to compile your script on my machine.
The problem was the very first property defining an alias which doesn’(t exists on my machine.
So I made some small changes to be able to compile.

Here is the edited version :


property csvAlias : ((path to desktop as text) & "SourceFiles:ean2sku.csv") --path to your csv-File as string to be able to compile on my machine
property csvDelimiter : "," --delimiter used by your csv-File


tell application "Finder"
	set this_folder to folder "HotFolder" as alias
	set itemList to every file in this_folder
end tell
try
	set TID to AppleScript's text item delimiters
	
	repeat with i from 1 to count of itemList
		set newFile to item i of itemList
		
		
		tell application "System Events" to set {fSuffix, fName} to {(name extension of disk item (newFile as text)), (displayed name of disk item (newFile as text))}
		
		if fSuffix is not "" then set fSuffix to "." & fSuffix
		set fName to my stripSuffix(fSuffix, fName)
		set tmpName to (text 1 thru 13 of fName)
		
		set csvText to read file csvAlias (*  to be able to compile on my machine *)
		
		if csvText contains tmpName then
			set AppleScript's text item delimiters to tmpName & csvDelimiter
			
			set newListName to (text 1 thru -1 of (paragraph 1 of (text item 2 of csvText)))
			
			if (count of fName) is greater than 13 then
				set newName to newListName & (text 14 thru -1 of fName) & fSuffix
			else
				set newName to newListName & fSuffix
			end if
			my renameFile(this_folder, fName & fSuffix, newName)
			
		end if
	end repeat
	
	set AppleScript's text item delimiters to TID
	
on error
	display dialog "Could not rename: " & fName giving up after 3
end try


on stripSuffix(fSuffix, fName)
	if fName contains fSuffix then
		set AppleScript's text item delimiters to fSuffix
		return (text item 1 of fName)
	end if
end stripSuffix

on renameFile(this_folder, origName, newName)
	set sourcePath to quoted form of POSIX path of ((this_folder as text) & origName)
	set targetPath to quoted form of POSIX path of ((this_folder as text) & newName)
	do shell script "mv -f " & sourcePath & space & targetPath
end renameFile


-- This areas then moves the files to the relevant folders

property type_list : {"TIFF", "JPEG", "PNGf", "PICT"}
property extension_list : {"tif", "tiff", "jpg", "jpeg", "png", "pict", "psd"}

set tFolder to ((path to desktop as text) & "HotFolder") as string

tell application "Finder"
	repeat with tFile in (get document files of folder tFolder whose name extension is in extension_list and (name does not start with "50" and name does not start with "MJC"))
		set nLayers to my getNumOfLayers(tFile as string)
		if nLayers < 5 then
			move tFile to the folder ((path to pictures folder from user domain as text) & "HotFolder2do") -- move to subFolder A
		else
			move tFile to the folder ((path to pictures folder from user domain as text) & "HotFolderDone")
		end if
	end repeat
end tell

on getNumOfLayers(f)
	((do shell script "/usr/bin/mdls -name kMDItemLayerNames " & (quoted form of POSIX path of f) & " | /usr/bin/wc -l ") as integer) - 2
end getNumOfLayers

May you try the script with a modified structure ?


property csvAlias : ((path to desktop as text) & "SourceFiles:ean2sku.csv") --path to your csv-File as string to be able to compile on my machine
property csvDelimiter : "," --delimiter used by your csv-File

-- This areas then moves the files to the relevant folders

property type_list : {"TIFF", "JPEG", "PNGf", "PICT"}
property extension_list : {"tif", "tiff", "jpg", "jpeg", "png", "pict", "psd"}


tell application "Finder"
	set this_folder to folder "HotFolder" as alias
	set itemList to every file in this_folder
end tell
try
	set TID to AppleScript's text item delimiters
	
	repeat with i from 1 to count of itemList
		set newFile to item i of itemList
		
		
		tell application "System Events" to set {fSuffix, fName} to {(name extension of disk item (newFile as text)), (displayed name of disk item (newFile as text))}
		
		if fSuffix is not "" then set fSuffix to "." & fSuffix
		set fName to my stripSuffix(fSuffix, fName)
		set tmpName to (text 1 thru 13 of fName)
		
		set csvText to read file csvAlias (*  to be able to compile on my machine *)
		
		if csvText contains tmpName then
			set AppleScript's text item delimiters to tmpName & csvDelimiter
			
			set newListName to (text 1 thru -1 of (paragraph 1 of (text item 2 of csvText)))
			
			if (count of fName) is greater than 13 then
				set newName to newListName & (text 14 thru -1 of fName) & fSuffix
			else
				set newName to newListName & fSuffix
			end if
			my renameFile(this_folder, fName & fSuffix, newName)
			
		end if
	end repeat
	
	set AppleScript's text item delimiters to TID
	
on error
	display dialog "Could not rename: " & fName giving up after 3
end try

set tFolder to ((path to desktop as text) & "HotFolder") as string

tell application "Finder"
	repeat with tFile in (get document files of folder tFolder whose name extension is in extension_list and (name does not start with "50" and name does not start with "MJC"))
		set nLayers to my getNumOfLayers(tFile as string)
		if nLayers < 5 then
			move tFile to the folder ((path to pictures folder from user domain as text) & "HotFolder2do") -- move to subFolder A
		else
			move tFile to the folder ((path to pictures folder from user domain as text) & "HotFolderDone")
		end if
	end repeat
end tell

-- Now the handlers.
(*
I edited this one *)
on stripSuffix(fSuffix, fName)
	if fName contains fSuffix then
		set oTIDs to AppleScript's text item delimiters
		set AppleScript's text item delimiters to fSuffix
		set prefx to (text item 1 of fName)
		set AppleScript's text item delimiters to oTIDs
		return prefx
	end if
end stripSuffix

on renameFile(this_folder, origName, newName)
	set sourcePath to quoted form of POSIX path of ((this_folder as text) & origName)
	set targetPath to quoted form of POSIX path of ((this_folder as text) & newName)
	do shell script "mv -f " & sourcePath & space & targetPath
end renameFile

on getNumOfLayers(f)
	((do shell script "/usr/bin/mdls -name kMDItemLayerNames " & (quoted form of POSIX path of f) & " | /usr/bin/wc -l ") as integer) - 2
end getNumOfLayers

Yvan KOENIG (VALLAURIS, France) mercredi 29 février 2012 21:28:13

I gave it a go, it seamed more fool proof to move them on to another folder first before running the action.

So all appears to be running smoothly now.

Thanks
for your help