Seeking Applescript pro for a file search operation

Joined
Oct 13, 2011
Messages
15
Reaction score
0
Points
1
Are you good with Applescript? If so I could definitely use your help.

All over my Mac's hard drive I have several files that begin with a 5 digit number in many different folders, i.e. "14452_car030.mov" and "12238_sidewalk060.mov"

Is there a way I can use Applescript to find every file that begins with file name "XXXXX" (where "XXXXX" is one of several hundred 5-digit numbers in a list- which I already have available). Then I would need it to move all those files to a specified folder. I wouldn't want it to copy and paste, but rather move, since I'm really just trying to wipe them off my Mac eventually.

The list of 5-digit numbers is over a thousand, and it's in .txt format (one per line). It looks something like this in notepad:

14452
12238
13345
15688
11920
etc.

And it would use this list to search for all files that start with "14452_etc." and all files that start with "12238_etc." and so forth. Your thoughts?
 
Joined
Aug 2, 2011
Messages
16
Reaction score
0
Points
1
G'day Feee99

How far did you get with this? Are you still looking for help?

m.
 
OP
F
Joined
Oct 13, 2011
Messages
15
Reaction score
0
Points
1
Yes, I am still looking for help, if you happen to know a solution. Sorry for this late reply.
 
Joined
Aug 2, 2011
Messages
16
Reaction score
0
Points
1
G'day

OK. I thought you were looking for help with an Applescript you were developing. It sounds like you are actually asking for a complete solution.

My apologies, I won't be able to work on this for the next few weeks but you'd probably be wanting to start with a spotlight search.
This will do a complete spotlight search of your machine and all associated volumes (but it will take a few minutes to run it) :
Code:
set mgFiles to get paragraphs of (do shell script "mdfind '(kMDItemFSName == \"*\")'")
If you know that all the files will be stored under a particular user then you'd restrict the search to speed things up (you need to change "macgrunt" to whatever your username is) :
Code:
set mgFiles to get paragraphs of (do shell script "mdfind  -onlyin /Users/macgrunt/ '(kMDItemFSName == \"*\")'")
If the files you are searching for are all .mov files then you'd add that to the filename to speed things up even more :
Code:
set mgFiles to get paragraphs of (do shell script "mdfind  -onlyin /Users/macgrunt/ '(kMDItemFSName == \"*.mov\")'")

Then you'd be wanting some repeat loops to compare your list of numbers with the results of the find. When it finds a match, you need to duplicate the found item to your new location before deleting the original item (ie. you can't 'move' files in the Finder with Applescript).

Sorry I can't help you more than that at this stage.
I'll get back to you with something more complete when I get a chance.

m.
 
OP
F
Joined
Oct 13, 2011
Messages
15
Reaction score
0
Points
1
Wow, this was a terrific help, thank you! It found all the .mov files on all three hard drives. They showed up in the Result field at the bottom of the Script Writer.

The ultimate goal is not to move the files, but to delete them. If we assume that deleting them within the Applescript is possible and would send them to the Trash, then I supposed I could glance through the Trash to double check the files when it's done.

The next step would be to have it look for the first five digits in all the .mov filenames, and comparing those digits to the list of 5 digit numbers in my .txt file. So, it would delete every .mov file which has its first 5 digits corresponding to any of the numbers in my .txt file.

My thinking is that I could drag the .txt file onto this Applescript, and it would run this process from there.

Thanks for following up. Even if this is something that would take a while, please let me know your thoughts on the feasibility of such an Applescript.
 
Joined
Feb 26, 2010
Messages
2,116
Reaction score
123
Points
63
Location
Rocky Mountain High, Colorado
Your Mac's Specs
1.8 GHz i7 MBA 11" OSX 10.8.2
You could also use terminal commands
Go to the highest level directory where all the movs are - in this example they are in my home directory under movies.
Code:
cd ~/Movies 
find . -name '[0-9][0-9][0-9][0-9][0-9]_*.mov' -print
The [0-9] is a regexp saying match a digit - you can change the range or set it to a specific digit - but there are 5 as you mentioned all movies have 5 digits and an _ (I think you mentioned the _) Anyway look here for more regular experssion magic.
http://www.regular-expressions.info/examples.html

This will show you all the files it finds. If this is to your liking then run the command with the -exec - you can either pass it to mv to move it to trash or rm to directly remove the file. Note - rm is final - there is no going back unless you use time machine so use these commands very very very carefully - especially with a recursive find.

To remove
Code:
find . -name '[0-9][0-9][0-9][0-9][0-9]_*.mov' -exec rm {} \;

To send to trash
Code:
find . -name '[0-9][0-9][0-9][0-9][0-9]_*.mov' -exec mv {} ~/.Trash \;
 
OP
F
Joined
Oct 13, 2011
Messages
15
Reaction score
0
Points
1
Would this be a drag and drop feature? Or, could I paste all the five digit numbers somewhere (as opposed to one at a time), and it would look for all of the files that start with those?

I wonder if there is software for searching for a long list of files... then I could just paste the 5-digit numbers into that... any ideas?
 

Shop Amazon


Shop for your Apple, Mac, iPhone and other computer products on Amazon.
We are a participant in the Amazon Services LLC Associates Program, an affiliate program designed to provide a means for us to earn fees by linking to Amazon and affiliated sites.
Top