Results 1 to 7 of 7
  1. #1
    Seeking Applescript pro for a file search operation

    Member Since
    Oct 13, 2011
    Posts
    15
    Seeking Applescript pro for a file search operation
    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?

  2. #2
    Seeking Applescript pro for a file search operation
    MacGrunt's Avatar
    Member Since
    Aug 02, 2011
    Posts
    16
    G'day Feee99

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

    m.

  3. #3
    Seeking Applescript pro for a file search operation

    Member Since
    Oct 13, 2011
    Posts
    15
    Yes, I am still looking for help, if you happen to know a solution. Sorry for this late reply.

  4. #4
    Seeking Applescript pro for a file search operation
    MacGrunt's Avatar
    Member Since
    Aug 02, 2011
    Posts
    16
    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.

  5. #5
    Seeking Applescript pro for a file search operation

    Member Since
    Oct 13, 2011
    Posts
    15
    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.

  6. #6
    Seeking Applescript pro for a file search operation
    IvanLasston's Avatar
    Member Since
    Feb 26, 2010
    Location
    Rocky Mountain High, Colorado
    Posts
    2,116
    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 \;

  7. #7
    Seeking Applescript pro for a file search operation

    Member Since
    Oct 13, 2011
    Posts
    15
    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?

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. MacBook Pro Erratic Operation
    By BigDWeav in forum Apple Notebooks
    Replies: 4
    Last Post: 10-06-2013, 11:26 PM
  2. Slow operation of Macbook Pro
    By Gaurang in forum Apple Desktops
    Replies: 1
    Last Post: 05-09-2013, 06:02 PM
  3. VMWare - Operation on file "dev/rdiskOs3" failed
    By mschmir in forum Running Windows (or anything else) on your Mac
    Replies: 2
    Last Post: 01-24-2011, 11:16 AM
  4. Applescript help: Find file, copy file
    By joseph2117 in forum OS X - Apps and Games
    Replies: 0
    Last Post: 09-19-2010, 08:47 AM
  5. Applescript to import buddies from file
    By Mentch in forum OS X - Apps and Games
    Replies: 1
    Last Post: 09-17-2008, 12:44 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •