Use Applescript to find files with certain conditions

I am using a tool to batch convert audio files in APE format to MP3. I have thousands of files located in hundreds of folders and subfolders in my hard drive so I searched for all APE/FLAC files and then dragged and dropped them in the tool for conversion. The problem is I was not able to convert all the files successfully for a variety of reasons (original APE files are corrupt, etc.), as a result I was left with a situation where some of the folders have files convernted (both APE and MP3 in that folder) whereas others don't (APE only). Instead of manually go to each folder and subfolder to find which ones need me to convert is there an Applescript I can use to quickly list the APE files that have not been converted?

Hello
You may try the following shell script. Please specify DIR as the root directory to start searching. It will create output list named no_mp3_list.txt on desktop.
#!/bin/bash
#     list every *.ape file which has no corresponding *.mp3 file in the same directory
#     * name matching is done in case-insensitive fashion
DIR=~/Desktop/test                # root directory to start scanning
OUT=~/Desktop/no_mp3_list.txt    # output file
shopt -s nocasematch
while read -d $'\0' f
do
    [[ -e "${f:0:${#f}-3}mp3" ]] || echo "$f" >> "$OUT"
done < <(find "$DIR" -iname '*.ape' -print0)
And in case, here's a simple AppleScript wrapper for the above, which lets you choose the root directory.
set f to (choose folder with prompt "choose root folder to start searching")'s POSIX path
if f ends with "/" then set f to f's text 1 thru -2
do shell script "/bin/bash -s <<'EOF' -- " & f's quoted form & "
#     list every *.ape file which has no corresponding *.mp3 file in the same directory
#     * name matching is done in case-insensitive fashion
DIR=\"$1\"                        # root directory to start searching
OUT=~/Desktop/no_mp3_list.txt    # output file
shopt -s nocasematch
while read -d $'\\0' f
do
    [[ -e \"${f:0:${#f}-3}mp3\" ]] || echo \"$f\" >> \"$OUT\"
done < <(find \"$DIR\" -iname '*.ape' -print0)
EOF"
Hope this may help,
H

Similar Messages

  • Smart Folders to find files with certain priviledges

    How do I set up a smart folder to display files that have only read&write privileges within a directory.

    You mmight have better success using a standard Finder search. In the Finder press Command-F and then you can apply various filters to isolate files based on kind, name, dates created/modified, and a large number of additional metadata criteria.
    If for some reason you can only find files that you have already modified (ie, by searching wiith modification date), then one way to reverse this for a search is to first find these files, then select them all and apply a Finder label to them (ie, "Red") and then perform the search on the same folders again but this time search for all items that are not labeled "Red" and your other items should show up.

  • Spotlight does not find files with "_" (underscores), but only for certain file types

    Hey Folks,
    this is strange, maybe someone has an idea.
    I already searched the internet for a while, nothing found so far.
    I have a file "calc_mean.m" on my desktop.
    When I type "calc" in spotlight, it shows the file.
    But when I type "calc_" it suddenly does not show the file anymore. Nor does find the file, when I enter "calc_mean.m" in spotlight.
    When I enter "calc mean.m" in spotlight, it finds it (using space instead of the underscore).
    Now comes the real surprise:
    When I rename the file to "calc_mean.txt", spotlight suddenly DOES find the file when entering "calc_mean.txt".
    I recreated this "feature" with other files, copying and renaming ".txt" files to ".m" files, and if there's a underscore in the file, spotlight wont find it.
    Playing around a bit more, it seems spotlight does find files with underscore when they are documents, at least it works for the following extensions:
    .pdf
    .doc
    .txt
    .xls
    But these extensions for example do not work:
    .mp3
    .m
    .k
    .a
    .ka
    (and other random endings I tried).
    I am pretty confused. Sure it's no big deal learning to search for files that include underscores in their name using space instead. But I'm still quite puzzled. Any idea?

    All of those have meaning in various database search syntax (not sure if it matters).
    _ usually means any character.
    % usually means any run of characters.
    - is often used to negate what comes next, i.e. "don't include results that have the following text."
    I don't see any problem on my Mac, though.
    I also don't have any problem finding file names with those accented characters using Spotlight. I would suggest reindexing Spotlight, but if cmd-f finds them, I'm not sure that would help.
    Spotlight: How to re-index folders or volumes

  • Using AppleScript to find specific text in mail message?

    I'm new to scripting, and I'm a bit lost on this one...
    Is there any way to use AppleScript to find a file name from within the body of a mail message so it can be used later in the script?
    Specifically, I want to use AppleScript to "read" the content of a mail message and look for a paragraph that says "Filename: MyFileName" so I can set "MyFileName" as a variable. (There will always be a paragraph that begins with "Filename: " in this particular email message.)
    This will part of a larger script that uses Fetch to download "MyFileName" from our FTP server.
    Thanks in advance for any ideas - I'm struggling with this one.
    Andy Gill

    Ok, red_menace above me had a shorter and more elegant solution to the question, I'm adding this just for another example.
    To solve your problem I'd make a mail rule that looked for any messages with "Filename:" in them (along with whatever criteria you wanted, like sender, domain, etc). The mail rule would execute the Applescript. My assumption is that the "Filename:foobar" text could be anywhere in the email, not necessarily the first thing in a paragraph, so I had to parse it differently.
    The results end up in a datalist, (theFilename {} ) that you can parse later to collect all filenames found in whatever messages were processed.
    I realize this could be cleaner, hope it's not hard to follow, but I did it really fast. It works flawlessly for me, picking out the name of the file no matter where in the email it appears.
    using terms from application "Mail"
    on perform mail action with messages theSelectedMessages for rule theRule
    repeat with aCounter from 1 to count theSelectedMessages
    set theMessage to item aCounter of theSelectedMessages
    set theContent to content of theMessage
    set theWords to every word of theContent
    set theFilename to {}
    set tid to AppleScript's text item delimiters
    set AppleScript's text item delimiters to ":"
    repeat with thisLoop in theWords
    try
    if (text item 1 of thisLoop) is "Filename" then
    set end of theFilename to (text item 2 of thisLoop)
    -- rest of your logic goes here the display is just to show it finds the filename, take it out!
    display dialog theFilename ¬
    buttons {"OK"}
    end if
    end try
    end repeat
    set AppleScript's text item delimiters to tid
    end repeat
    end perform mail action with messages
    end using terms from
    Message was edited by: stephen.bradley Typos for the win!

  • Spotlight fails to find files with search items

    I just did a Spotlight search on
    Japanese English は
    Spotlight found more than 3500 items, but the two sample Word files I looked at didn't have は in them.
    This is really frustrating. Is there a way to ensure Spotlight only finds files with the input?

    Spotlight is notorious for its weaknesses and erratic behavior. You might try reindexing your Spotlight. Open up Spotlight in Sys Prefs, go to Privacy and drag the HD Folder there. Leave it a minute then remove it by clicking on the minus at the bottom. This will force Spotlight to reindex the drive, which may take some time.
    I mostly use EasyFind (free) instead of Spotlight.
    http://www.devon-technologies.com/products/freeware/

  • Script to find files with same names with in a folder and it sub folders.

    Looking for script to find files with same names with in a folder and it sub folders.

    Are you just looking to find if any two files underneath a folder have the same name?
    If you just want to know that a file named "whatever" exists in two folders, that's not too difficult, but you probably want to know the full path names.
    Here's one attempt:
    $ perl -MFile::Find -le 'find(\&w, "."); while (($n,$p)=each %file) {if(@{$p}>1){print join(" ",@{$p})}} sub w{push @{$file{$_}},$File::Find::name;}'That will print the pathnames on the same line of any files with the same name that appear anywhere underneath your current directory.
    It's a bit long for a "one-liner", but functional.
    Darren

  • What application can you use to open a file with the .acc extension?

    What application can you use to open a file with the .acc extension?

    http://www.fileinfo.com/extension/acc

  • Using AppleScript to sort files Into Specified Folders based on Extension

    Hi All!
    Here is what I am trying to figure out. I would love some help with this script if anyone can lend a helping hand. I am currently using Hazel to do this but I think AppleScript will be alot more effective.
    Situation:
    - I have a folder with 4 different file types inside - the extensions are (.cop, .cof, .cos, .cr2)
    - These files need to be organized in this folder structure  Captureone > Cache > Proxies
                                                                                                                  > Settings50
    - The .cop & .cof files both need to be put in the "Proxies" folder
    - The .cos needs to be put in the "Settings50" folder
    - The .cr2 can stay where it is.
    I'm already using an AppleScript application where it automatically creates the folder structure in the current finder location, which works great. I use a program named Hazel to sort the files automatically into the folders where they need to go. Unfortunately all my computers at work don't have Hazel and I would like help to make a script. Any thoughts to add to my existing script?
    #  define a list of folders - items will need to be quoted if they contain spaces, etc.
    property theFolders : {"Captureone/Cache/Proxies", "Captureone/Settings50"} -- can also nest, e.g. "Inside/One"
    try
              tell application "Finder" to set targetFolder to (target of the front window) as alias
    on error -- no window
              set targetFolder to (choose folder)
    end try
    # build a parameter string from the folder list
    set {tempTID, AppleScript's text item delimiters} to {AppleScript's text item delimiters, space}
    set {theFolders, AppleScript's text item delimiters} to {theFolders as text, tempTID}
    do shell script "cd " & quoted form of POSIX path of targetFolder & "; mkdir -p " & theFolders

    Hi,
    applescript_problems wrote:
    for example:
    master folder name: 1
    sub folder path: 1>2>3>4>5
    insdie folder 5 theirs 3 folders: 5a, 5b, 5c
    i want to name my files like so: "name_5a" "name_5b" "name_5c
    i want the scrip to pick up all the files that ends with the name "_5a" and place them in folder 5a
    I presume that the files are in the master folder not in the subFolders, that the files has an name extension.
    This script take the first two characters after the last underscore.
    It will move the file in the subfolder, according to the two characters found.
    set targetFolder to (POSIX file "") as alias --<-- drop the master folder between the double quotes
    tell application "Finder"
          repeat with tFile in (get files of targetFolder)
                set tName to name of tFile
                set subname to my getChar_1_2AfterLastUnderscore(tName)
                -- example : subname = "5c" -->  folder "5c" of folder "5" of targetFolder
                if subname is not "" then
                      tell folder subname of folder (text 1 of subname) of folder targetFolder
                            if exists then move tFile to it -- if exists this folder then move this file
                      end tell
                end if
          end repeat
    end tell
    on getChar_1_2AfterLastUnderscore(t)
          if "_" is in t then try
                set oTID to text item delimiters
                set text item delimiters to "_"
                set t to text 1 thru 2 of last text item of t
                set text item delimiters to oTID
                return t
          on error
                set text item delimiters to oTID
          end try
          return ""
    end getChar_1_2AfterLastUnderscore
    To get the exact path of the master folder :
    Drag/drop the folder between the double quotes in the first line of the script.

  • How to use elements in .css file with javascript in the jsp

    I have a jsp in which i need to show some links with the background colour.The links depends on certain conditions which is known.But the requirement is that the background color should be grey and white alternatively. I could have hardcoded the background color with the link. But the problem is that all the links are not visible to all users. The background color is defined in the .css file. I need to check the background color for the previous link. I am declaring a boolean within a jsp and then verifying the value of that boolean( in the javascript within the same jsp) so that i could know the bckground color for previous link.but i am not able to use the element in the .css element in that javascript which is having if-else loop.It's showing an error when i tried doing this. So can some one help me out how can this be done.

    Hi Shweta,
    Refer this [wiki|https://wiki.sdn.sap.com/wiki/display/Snippets/ABAP-TableDisplayinSAPScript]
    Regards,
    Sravanthi

  • Trying to write an Automator program to find files with same time created and change file names to matching source folder names

    I am failrly green when it comes to automator.
    I am trying to write an Automator program:
    Not sure where to post this
    trying to write an Automator program to find files and alter their names
    I have a source folder with correct named master files in it.
    eg. A0001_1234.mpeg
    time created 14:02:03
    date 07/07/2012
    Another folder where there will be copies of the master files in a different format with different names but created at the same time as a file in the source directory.
    they are created with a seperate device but they are
    A0000001.mp4
    time created 14:02:03
    date 07/07/2012
    I need it to then take the name from the source fies and apply the correct name to the matching file based on the time it was created.
    I can't seem to find actions in automator that reference time crated.
    Is this something I will be able to Do in automator?
    Any help would be great
    Thanks
    R

    Hi,
    It's impossible to do this without any script in Automator.
    Use this AppleScript script :
    set source to choose folder with prompt "Select the source folder"
    set anotherfolder to choose folder with prompt "Choose the another folder"
    tell application "Finder"
        repeat with tfile in (get files of source)
            set cDate to creation date of tfile
            set findFiles to (files of anotherfolder whose creation date is cDate)
            if findFiles is not {} then
                set tName to name of tfile
                set name of item 1 of findFiles to tName
            end if
        end repeat
    end tell

  • Making a single field editable with certain conditions

    Hi,
    We have an requirement wherein only a single field in an read only BC should be editable(with a certain condition).
    Kindly help me on this.
    Thanks and Regards,
    Priya

    Hi,
    The only way is put the "condition" in a calculated field. Create one more applet (clone of the read only applet). Make all the other fields read only at "applet level" and leave the one field as editable. Use the calculated field to toggle the cloned applet. Thats it. Any query revert back.
    Regards,
    Joseph

  • Help! Cannot open files with certain applications

    I updated to OS Tiger from OSX some weeks ago. Before, I could run a program that labels files in a given folder with names given in an Excel file (csv format). This "csv sorter" usually asks for the csv file once I put in the folder with the files that should be labeled. In the dialog window that opened I could just go through my harddrive to my csv file and choose it. Now the csv files always appear in pale grey and I cannot click on them. Has anybody an idea why certain programs should not recognize certain filetypes any more in OS Tiger? It seems like I cannot access any file with the csv sorter any more, no matter which file type. Thanks for your help!

    found this on another websites forum .... it worked
    I figured it out. Thanks everyone!
    I had to turn on my wireless mouse... And even though I wasn't using my wireless mouse and just the trackpad...I had to turn on my wireless mouse then adjust those settings...Had to turn down the speed. Then Once I shut the mouse off and started to use the trackpad again it works perfectly.
    I'm not sure why the mouse settings would change the trackpad settings but it did.

  • Viewing comments by default; finding files with comments

    I searched the various preferences but did not see this: Is there a way to tell Acrobat to open files with the comments list showing?
    Also, I have a folder of PDFs that have been indexed with catalog. Only a few of the files have comments. Is there any way to construct a search for "any PDF with a comment"?  What I've been doing is using the user ID that Acrobat automatically places in edits, but that won't help for long, as the number of people doing comments will increase, and some future documents will have those IDs in regular text.

    LarryHN:
    1) your suggestion will not work for the issue I'm describing: if I have both Raw and Jpeg files of the same image on my SD card, the iPad sort of lumps these together, so when I view the contents of my SD card it shows as one image/file, and if I select it and download it, it brings over both the Raw and Jpeg versions of the image, which is what I am trying to avoid and why I started the tread in the first place.
    2) I spoke with sales people at two Apple stores and one person with their online sale, and none of them could addrss my issue. The online sales person said she might have to put me through to their tech people to resolve this or at least get the full, correct info. None of them were janitors.
    I did find a workaround which I think will work:
    Download the files over to my iPad, then use an app like Photo Manager Pro to be able to view the files by type, then select the Raw files and delete them from my iPad. This will work I hope, but seems like a lot of extra work for a device that's supposed to be user friendly--I think Apple missed the boat on this one, opting for making things 'simple' instead of functional for photographers.

  • Finding file with Spotlight

    How do I find a file with Spotlight? Or, more to the point, why does Spotlight make it soooo hard to find the location of files?
    Example: I want to find file "foo.xls". I type in "foo.xls" into Spotlight and sure enough, there it is! Great! Er .. but wait. All Spotlight lets me do is OPEN the file. I don't want to do that, I just want to know where it is; what folder it is in.
    How do I do that? I can't right-click on items in the Spotlight result list (why not? isn't this what most users would do?). I can't press spacebar for quicklook. I can't seem to do ANYTHING with Spotlight EXCEPT open the file.
    I presume there is some hidden shortcut key involving some obscure combination of option+command etc etc, but how am I supposed to know that? Isn't this supposed to be easy?
    This is, to say the least, very frustrating.
    --Tim

    In 10.6 and prior, the user would need only hover over the item in Spotlight's results and a yellow flag would appear with the location. In 10.7, a new Spotlight feature emerged, the preview, so the yellow flag is gone.
    Use Finder's Spotlight instead in the upper right of the Finder window. You can always use Finder's "Show Path Bar" view, so that, after doing a Finder Spotlight search, you can single click on a file and see the path listed at the bottom of the window.

  • Find files with key words

    trying to find files using key words is not working using bridge with cs3 and windowsxp.
    when key words are attached to a file they are evident when the image is open. when i try to search for the file using the selected key word i get a no results found response.
    any suggestions

    Lots of posts on this subject in the Bridge forum. Check there, and if you still have problems post question.

Maybe you are looking for

  • Getting the page of a link

    hello forum I use applescript to automate indesign. now I've to do a job, where I make textframes on a new layer, same size and position as image/grafic-objects on other layers. to do this, I check the links of the document. if there are more than on

  • IPhoto 5 has better quality that iPhoto 6 when emailing photos?

    How can I set up iPhoto 6 to use the same image quality as iPhoto 5 when emailing photos? I have two iMacs, side by side, one is G5 with iPhoto 5, and another is Intel with iPhoto 6. When I use iPhoto 5 to email a photo, medium quality 640x480, it lo

  • Subject areas and connection pools

    Hi, Could you let me know what is the best option for me. We have tables coming from single data source. We are doing diffferent subject areas based on the requirements. My question is is it best to do different connection pools for each subject area

  • [SOLVED] Why does my JAVA_HOME point to jre instead of jdk?

    I am having a strange phanomenon. I have jdk7-openjdk installed, but I still have % echo $JAVA_HOME /usr/lib/jvm/java-7-openjdk/jre This is only with my current user. When I try root or a freshly created user, I correctly get % echo $JAVA_HOME /usr/l

  • Competencies Descriptions does not show up

    Hello, I am inserting competencies/ objectives through an implementation of HRHAP00_ENHANCE_FIX BADI. Appraisal document contains the competencies/ objectives correctly. Meanwhile, when I double click on them, description does not appear. At BADI, I