Need help writing a script to traverse through files in a directory

I want to go through a directory and sub directories and convert files into jpg ones
I have this code I've been using: mkdir jpegs; sips -s format jpeg *.png --out jpegs
This is great for one directory at a time
But, what I want is to apply this to all sub directories, create a jpeg directory in each of the sub directories and then create jpg's and put them in there
I'm not sure where to start
Should I be looking for 'scripting in linux'?
Thanks
Omar

Hello
You may also try something like this. Set DIR to the root directory to start the search.
#!/bin/bash
#     convert png to jpeg and put jpeg in jpegs sub-directory
DIR=~/Desktop/test
while read -d $'\0' f
do
    d=${f%/*}/jpegs
    [[ -d "$d" ]] || mkdir "$d"
    sips -s format jpeg "$f" --out "$d"
done < <(find "$DIR" -type f -iname '*.png' -print0)
In case, here's an AppleScript wrapper:
set f to (choose folder with prompt "Choose root folder to process")'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 & "
#     convert png to jpeg and put jpeg in jpegs sub-directory
DIR=\"$1\"
while read -d $'\\0' f
do
    d=${f%/*}/jpegs
    [[ -d \"$d\" ]] || mkdir \"$d\"
    sips -s format jpeg \"$f\" --out \"$d\"
done < <(find \"$DIR\" -type f -iname '*.png' -print0)
EOF"
Regards,
H

Similar Messages

  • I need help writing a script that finds the first instance of a paragraph style and then changes it

    I need help writing a script that finds the first instance of a paragraph style and then changes it to another paragraph style.  I don't necessarily need someone to write the whole thing, by biggest problem is figuring how to find just the first instance of the paragraph style.  Any help would be greatly appreciated, thanks!

    Hi,
    Do you mean first instance of the paragraph style
    - in a chosen story;
    - on some chosen page in every text frames, looking from its top to the bottom;
    - in a entire document, looking from its beginning to the end, including hidden layers, master pages, footnotes etc...?
    If story...
    You could set app.findTextPreferences.appliedParagraphStyle to your "Style".
    Story.findText() gives an array of matches. 1st array's element is a 1st occurence.
    so:
    Story.findText()[0].appliedParagraphStyle = Style_1;
    //==> this will change a paraStyle of 1st occurence of story to "Style_1".
    If other cases...
    You would need to be more accurate.
    rgds

  • Need help writing a script

    I am trying to convert my prcess from DTS to SSIS. I am running this report out of SAP and then using Monarch to put into the correct form, then I am using the DTS to put it into the database on the SQL server.  I am able to get all the other info to
    move out having so much trouble here to get the plant number. The issuse is that it is on top on the page and it will change when a new plant is needed.
    Thanks for any help
    I need help wrting a script that will put that 7010 into a cloumn nnamed plant number.

    To convert from DTS packages to SSIS you can just open the DTS package in a new SSIS project (depends on target SSIS version by using SSDT or BIDS).
    The rest is mechanics how the iteration with SAP is done and may be beyond the scope of this forum.
    Arthur
    MyBlog
    Twitter

  • Need help writing a script to delete a folder to run at startup

    I have no experience with this and need full assistance to set this up.
    I am hoping to write a script which can be run at startup on a single client machine which is giving me font trouble. Our client machines are network controlled by our server and have multiple users all in the Server user database.
    The fonts are behaving badly until we trash this folder HD>Library>Caches>com.apple.ATS
    On restart the fonts behave as expected.
    Can someone help me write a script or give me a command I can insert in a crontab with Cronnix to delete this folder at startup?
    Thanks

    They both work fine (read that as: it can be added into either place) While that message in crontab seems to intimate that Apple will do something drastic like disable or make it hard to run cron I cannot see how, cron has been in all *nix's since the beginning so to remove it would anger quite a few people...
    Having said that, If you want to make a launchd item you would put the below into /Library/LaunchDaemons/ create a file (call it someting memorable like 'Delete_com.apple.ATS') put this into it:
    Code:
    <?xml version="1.0" encoding="UTF-8"?>
    <!DOCTYPE plist PUBLIC "-//Apple Computer//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
    <plist version="1.0">
    <dict>
    <key>Label</key>
    <string>Delete com.apple.ATS</string>
    <key>ProgramArguments</key>
    <array>
    <string>rm</string>
    <string>-rf</string>
    <string>/Library/Caches/com.apple.ATS</string>
    </array>
    <key>RunAtLoad</key>
    <true/>
    </dict>
    </plist>
    and finally load it...
    PowerMac G5 DP 2.5Ghz   Mac OS X (10.4.3)  

  • [Updated topic] Need help writing a script

    Hey all!
    Got a folder with about 100 *.sql files and been trying to use the folowing python script to import them into the database:
    #!/usr/bin/env python
    import glob, os
    patches = glob.glob('*.sql')
    patches = sorted(patches)
    for x in patches:
    db = x.split("_")[2].replace('.sql', '')
    os.system("mysql -u mangos -ppassword -v " + db + " < " + x)
    But i get an error like this:
    File "/opt/mangos/sql/updates/update.py
    db = x.split("_")[2].replace('.sql', '')
    IndexError: list index out of range
    Tried different numbers instead of the [2], any clues?
    FYI not very hightech python-guru
    Last edited by Afnaf (2010-07-14 11:58:31)

    This isn't python, but here's what I do:
    1) I have a bash script called _genspscript.sh which contains the following:
    #!/bin/bash
    rm _spscript.sql
    cat *.sql > _spscript.sql
    2) Run that script and it creates a single .sql file with all the SPs in them. Then I just run that one file into MySQL.
    (Shameless plug: If you're interested I also have a Python script that will read the Schema of a DB and create the basic CRUD stored routines in individual files for all tables in a MySQL DB.)

  • Need Help Creating A Script For Labeling Finder Files from Indesign

    Trying to figure out a way to have a script run in InDesign CS4 that will label a text file RED after it's been imported into InDesign.
    We import numerous text files into an InDesign template. Since there are several text files in the same folder, we need to somehow "mark off" that we've imported that file and move to the next one to import. I have created an Automator "service" with a keyboard shortcut to label the file Red in the finder but it would be great if we could have this happen automatically after we import into InDesign.
    If we import the wrong text file by accident and it gets missed in proofing, it costs us a lot of money with the printer.
    Thanks for any ideas.
    Jim

    You know, these guys are absolutely right in their assessment that this is a good place for event listeners. You would need three scripts though.
    Something like...
    Label Placed Files Red.scpt
    --Put this in a folder called IDScripts in your Documents folder
    main(evt)
    on main(myEvent)
    tell application "Adobe InDesign CS4"
    set placedFilePath to full name of myEvent
    set placedFilePath to placedFilePath as alias
    end tell
    tell application "Finder"
    --This turns the file color red
    set label index of placedFilePath to 2
    end tell
    end main
    And these two are in your InDesign scripts folder...
    Start Placed File Finder Labelling.scpt
    --Installs the afterImport event listener for the Label Placed Files Red script.
    tell application "Adobe InDesign CS4"
    set myHandler to path to documents folder
    set myScriptName to "Label Placed Files Red.scpt"
    set myHandler to "" & myHandler & "IDScripts:" & myScriptName
    try
    set myHandler to myHandler as alias
    make event listener with properties {event type:"afterImport", handler:myHandler, captures:true}
    display dialog "Placed File Labelling: ON" buttons "OK" default button 1
    on error
    display dialog "ERROR: Couldn't start handler!" & return & return & "Make sure the \"" & myScriptName & "\" script in a folder called \"IDScripts\" inside your Documents folder and try again" buttons "OK" default button 1
    end try
    end tell
    Stop Placed File Finder Labelling.scpt
    --Removes the afterImport event listener for the Label Placed Files Red script.
    tell application "Adobe InDesign CS4"
    set myHandler to path to documents folder
    set myScriptName to "Label Placed Files Red.scpt"
    set myHandler to "" & myHandler & "IDScripts:" & myScriptName
    set myHandler to myHandler as alias
    set myResult to remove event listener event type "afterImport" handler myHandler with captures
    if (myResult is false) then
    display dialog "ERROR: Couldn't remove handler! Are you sure it is active?" & return & return & "If so, please quit and relaunch InDesign to get rid of it." buttons "OK" default button 1
    else
    display dialog "Placed File Labelling: OFF" buttons "OK" default button 1
    end if
    end tell

  • Need Help Writing Server side to submit form via API

    Hey
    I need help writing a serverside application to submit
    information via API to a separate server.
    I have a client that uses constant contact for email
    campaigns. We want to add to her website a form taht submits the
    information needed to subscribe to her email list, to constant
    contact via API.
    FORM.asp :: (i got this one under control)
    name
    email
    and submits to serverside.asp
    SERVERSIDE.ASP
    In serverside.asp i need to have
    the API URL
    (https://api.constantcontact.com/0.1/API_AddSiteVisitor.jsp)
    username (of the constant contact account)
    password (of the constant contact account)
    name (submited from form.asp)
    email (submitted from form.asp)
    redirect URL (confirm.asp)
    Can anyone help get me going in the right direction?
    i have tried several things i found on the net and just cant
    get anyone to work correctly.
    One main issue i keep having is that if i get it to submit to
    the API url correctly - i get a success code, it doesnt redirect to
    the page i am trying to redirect to.
    ASP or ASP.NET code would be find.
    THANKS
    sam

    > This does require server side programming.
    > if you dont know what that is, then you dont know the
    answer to my question. I
    > know what i need to do - i just dont know HOW to do it.
    If you are submitting a form to a script on a remote server,
    and letting
    that script load content to the browser, YOU have no control
    over what it
    loads UNLESS there is some command you can send it that it
    will understand.
    No amount of ASP on your server is going to change what the
    remote script
    does.
    http://www.constantcontact.com/services/api/index.jsp
    they only allow their customers to see the instructions for
    the API so i
    can't search to see IF there is a redirect you can send with
    the form info.
    But posts on their support board say that there is.
    Alan
    Adobe Community Expert, dreamweaver
    http://www.adobe.com/communities/experts/

  • Need help writing host program using LabView.

    Need help writing host program using LabView.
    Hello,
    I'm designing a HID device, and I want to write a host program using National Instrument's LabView. NI doesn't have any software support for USB, so I'm trying to write a few C dll files and link them to Call Library Functions. NI has some documentation on how to do this, but it's not exactly easy reading.
    I've written a few C console programs (running Win 2K) using the PC host software example for a HID device from John Hyde's book "USB by design", and they run ok. From Hyde's example program, I've written a few functions that use a few API functions each. This makes the main program more streamlined. The functions are; GetHIDPath, OpenHID, GetHIDInfo, Writ
    eHID, ReadHIC, and CloseHID. As I mentioned, my main program runs well with these functions.
    My strategy is to make dll files from these functions and load them into LabView Call Library Functions. However, I'm having a number of subtle problems in trying to do this. The big problem I'm having now are build errors when I try to build to a dll.
    I'm writing this post for a few reasons. First, I'm wondering if there are any LabView programmers who have already written USB HID host programs, and if they could give me some advice. Or, I would be grateful if a LabView or Visual C programmer could help me work out the programming problems that I'm having with my current program. If I get this LabView program working I would be happy to share it. I'm also wondering if there might already be any USB IHD LabView that I could download.
    Any help would be appreciated.
    Regards, George
    George Dorian
    Sutter Instruments
    51 Digital DR.
    Novato, CA 94949
    USA
    [email protected]
    m
    (415) 883-0128
    FAX (415) 883-0572

    George may not answer you.  He hasn't been online here for almost eight years.
    Jim
    You're entirely bonkers. But I'll tell you a secret. All the best people are. ~ Alice

  • Need help writing small program!

    Hi. I'm learning Java programming, and I need help writing a small program. Please someone help me.
    Directions:
    Create a program called CerealCompare using an if-then-else structure that obtains the price and number of ounces in a box for two boxes of cereal. The program should then output which box costs less per ounce.

    class CerealCompare {
        public static void main(String[] args) {
            // your code goes here
    }Hope that helps.
    P.S. Java does not have an if-then-else statement.

  • HT2480 I need help syncing my computer outlook email (through Yahoo) with my Iphone. when I delete an email on my computer is it still in my inbox on my phone.  Any help is appreciated.

    I need help syncing my computer outlook email (through Yahoo) with my iphone.  When I delete an email on my computer it is still in my inbox on my phone. Please help.

    Your computer is probably set up to access your Yahoo mail using POP3. POP3 does not synchronize with the server. For full synchronization, you will need to use IMAP instead. See the Yahoo mail help pages for instructions on how to configure your mail client.

  • How can i traverse between files in a directory

    how can i traverse between files in a directory. I ahve seen in the site that isFile can be used to switch from one file to other but i didn't found such method. I am working in Eclipse. I would be thankful if u send me the solution.I mean the way to traverse

    listFiles() returns all the files in a directory. You can check if it is a file and read it. Read the API docs.
    If you have specific problem with your code, post the code and the problem description.

  • Search through files in a directory

    How do I get a list of the files in a directory? I am aware of JFileChooser but it is not what I am looking. I need to search the contents of the xml files in the directory. I can do this with one file but need to do it with them all.

    // where files in subdirectory \files below the application directory
    File dir = new File(".\\files\\");
      if(dir.exists()){
        File[] list = dir.listFiles();
        for (int i = 0; i < list.length; i++){
          String fileName = list.toString();
    int iPtr = fileName.lastIndexOf("\\");
    int jPtr = fileName.indexOf(".xml",0);
    if (jPtr>-1) {
    String longName = fileName;
    String shortName = fileName.substring(iPtr + 1, jPtr);
    // file name in short name

  • Need help  traversing through files

    i have a folder with 99,999 xml files. i need to access each and everyone of these files to look for a certain value.my question is: is there any convenient way of traversing through these files?
    File xmlfile = new File("");
    File onefolder = new File("C:\\Documents and Settings\\drstempprojects\\Desktop\\Compiled\\NLB_Recam");
    String[] arroffiles = onefolder.list();
    for (int i=0;i<arroffiles.length;i++) {
        xmlfile = new File("...\\NLB_Recam\\" + arroffiles);
    this method is inefficient and takes a hell load of memory since we are creating an array of 99,999 strings and using each array slot only once. i'm pretty sure there are better solutions to this. suggestions pls anyone?thanks.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                               

    i'm pretty sure there are better solutions to this. suggestions pls anyoneDon't store 100k files in the same directory.

  • Need Help Writing a Shell Script

    Basically I'm writing a script that opens TextEdit so I can open it from the Terminal. I also want it to run in the background so I can continue using the Terminal without having to quit TextEdit first. So far I've figured out two ways of doing this, and neither one does exactly what I want it to do. Here's the first one I tried:
    /Applications/TextEdit.app/Contents/MacOS/TextEdit $@ &
    The problem with this is that if TextEdit is already running, it opens a new instance of it to open the files, and it doesn't bring the app into focus when I run it. So I decided to try this:
    open -a "TextEdit" $@ &
    This way all files open in the same instance of TextEdit and it brings the app to the front, but it won't let me save anything I don't have write privileges for, even if I run it with sudo. I Googled it and apparently what happens is it runs "open" as root but runs the actual application that I'm opening as the current user.
    So basically what I need to know is if there's a way of doing this that will congregate all files into the same instance of TextEdit and bring the app to the front when I launch it, but still let me run it as root with sudo. If not, is there at least a way to check if TextEdit is running and throw an error if it is?

    #!/usr/bin/env bash
    if ps ax | grep '[T]extEdit'; then
    echo "TextEdit is already running!"
    else
    /Applications/TextEdit.app/Contents/MacOS/TextEdit &
    fi
    open -a TextEdit "$@"
    osascript -e 'tell application "TextEdit" to activate'
    Example:
    your.script "text file.txt"
    NOTE 1: When posting code to this forum, enclose your code in
    ...your code goes here...
    This will make sure that all your indentation and other meta-characters that might get interpreted by the forum code will be left alone.
    NOTE 2: The $@ will ONLY preserve quoted strings as a single argument if it is specified as "$@". That is to say it MUST be inside a pair fo double-quotes. Otherwise it is the same as $* The missing ".." are what messed up your ability to treat a file with space as a single argument. ALSO NOTE, I specified the file on the command line inside quotes (could be single or double), or you could use  if you desire.
    NOTE 2 and a half:
    If you DO NOT want to put quotes around the space filled filename when invoking your script, you could change your "$@" to "$*"
    open -a TextEdit "$*"
    The difference is that using "$@" will allow specifying several filenames on the command line and TextEdit will open all of them at once. The use of "$*" means you can only open 1 file per use of your script. Not a big deal, but I figured you should know the options available to you.
    NOTE 3: I've simplified your script.
    I do not know why you decided that if you are root you wanted to use sudo, since sudo gives normal users root privileges, and root already has root privileges.
    Actually based on earlier exchanges, I would have thought that you wanted to start TextEdit using sudo, unless it was already running:
    sudo /Applications/TextEdit.app/Contents/MacOS/TextEdit &
    so that you had root privileges allowing you to write files in places you were normally not allowed. Then again, maybe I was reading the earlier posting wrong (won't be the first time ).
    NOTE 4: The use of
    if [ "$textedit" > /dev/null ]; then
    is just plain wierd This translates to the command:
    test "$textedit" >/dev/null
    which redirects standard output into /dev/null, so the actually command looks like
    test "$textedit"
    which will essentially return TRUE if $textedit has a string in it, and FALSE if $textedit is empty.
    I decided to just use the completion status of the grep command as a way to decide if TextEdit was running on not.
    NOTE 5: I simplified the ps|grep|grep command with a trick I learned several years ago. The '[T]extEdit' regular expression exactly matchs TextEdit, except that it DOES NOT match a ps line that has '[T]extEdit'. So I can get rid of one grep command because it will never match the grep command in the ps output.
    NOTE 6: I moved the open and osascript commands outside the if structure, as I assumed you wanted osascript to bring TextEdit to the foreground regardless of whether it was already running or not, and the open command was identical for both halfs of the if structure. If this is a bad assumption, feel free do put it back inside the if structure.
    Message was edited by: BobHarris

  • Need help writing script to change version control for all document libraries in all sites

    Hello,
    I found this script, http://get-spscripts.com/2010/10/changing-sharepoint-list-settings-using.html that
    changes versions control for a document library.  However, many sites have many document libraries with different names.  The script below just changes a the settings to a document library that is named "Shared Documents", but does not
    change one if its named something else.  How can change the script to loop through all document libraries so their settings are changed?
    $site = Get-SPSite http://site
    $listName = "Shared Documents"
    #Walk through each site in the site collection
    $site | Get-SPWeb | 
    ForEach-Object {
    #Get the list in this site
    $list = $_.Lists[$listName]
    #Create a version each time you edit an item in this list (lists)
    #Create major versions (document libraries)
    $list.EnableVersioning = $true
    #Create major and minor (draft) versions (document libraries only)
    $list.EnableMinorVersions = $true
    #Keep the following number of versions (lists)
    #Keep the following number of major versions (document libraries)
    $list.MajorVersionLimit = 7
    #Keep drafts for the following number of approved versions (lists)
    #Keep drafts for the following number of major versions (document libraries)
    $list.MajorWithMinorVersionsLimit = 5
    #Update the list
    $list.Update()
    #Dispose of the site object
    $site.Dispose()
    Paul

    Sorry, I agree. It will update Style Library and other out of the box ones. Include the library titles in a collection and run the update against them provided these libraries are common across all sites. If not, you will have to first get an extract of
    all such libraries in all sites say in a CSV file and then update the script below to refer to the CSV records.
    Add-PSSnapin "Microsoft.SharePoint.PowerShell" -ErrorAction Stop;
    #List of Libraries to be updated.
    $Libraries = @("Shared Documents","My Document Library");
    $spAssgn = Start-SPAssignment;
    $site = Get-SPSite http://site -AssignmentCollection $spAssgn
    #Walk through each site in the site collection
    $site | Get-SPWeb -Limit ALL -AssignmentCollection $spAssgn |
    ForEach-Object {
    #Enumerate through all document libraries
    $_.Lists|Where{$_.BaseTemplate -eq "DocumentLibrary" -and $Libraries -contains $_.Title}|Foreach-Object{
    #Get the list in this site
    $list = $_;
    #Create a version each time you edit an item in this list (lists)
    #Create major versions (document libraries)
    $list.EnableVersioning = $true
    #Create major and minor (draft) versions (document libraries only)
    $list.EnableMinorVersions = $true
    #Keep the following number of versions (lists)
    #Keep the following number of major versions (document libraries)
    $list.MajorVersionLimit = 7
    #Keep drafts for the following number of approved versions (lists)
    #Keep drafts for the following number of major versions (document libraries)
    $list.MajorWithMinorVersionsLimit = 5
    #Update the list
    $list.Update()
    Stop-SPAssignment $spAssgn;
    This post is my own opinion and does not necessarily reflect the opinion or view of Slalom.

Maybe you are looking for

  • OKI C301 laser printer stopped functioning after latest OSX security update

    Hi, The printer was functioning perfecty before the update. It is connected to the the router and through Wi-Fi with an iMac and a MacBook Air. After updating to 10.9.2 it pops an error message when trying to print anything. Here are the first lines

  • My wife can no longer access her email

    She suddenly lost the ability to receive email through thunderbird although she could send. The provider, century link, changed her password in an attempt to fix. I was able to access her address list but now she has lost past emails and still cannot

  • Select-option in display mode

    HI ABAP Gurus, In selection screen i want to make selectoption/parameter field in displaymode( User cant change that field it shud appear but in display mode). Plz help me regarding this. I am using At selection-screen output for this as declaring Mo

  • Fails to check out an application module error calling web service

    I am using the ServiceFactory code to invoke the TerritoryProposalPublicServiceImpl.findProposals web service method. Weird thing is it invokes the service method for the first time, second time it throws the following error. Please help Jul 20, 2011

  • How-to retrieve the address book of a Leopard CCC backup?

    Hi, I have installed SnowLeopard and before doing so, I did a CarbonCopyCloner backup of Leopard. I forgot to export my address book of Leopard and now I want all my contacts back in the SnowLeopard address book. How can I do? What are the files I ha