AppleScript to Select Groups of 3 Files?

Hi all,
Thanks in advance for any help you can provide. I am trying to create an AppleScript to take groups of 3 files and put them each in their own folder, inside of a master container folder. The files will typically be in DNG format as they will be from my digital camera—3 exposures of the same scene.
Input example: folder containing files IMG_0022.dng, IMG_0023.dng, IMG_0024.dng, IMG_0025.dng, ... IMG_0052.jpg
Output example:
Container folder hdr_images
folder images_group1
IMG_0022.dng
IMG_0023.dng
IMG_0024.dng
folder images_group2
IMG_0025.dng
IMG_0026.dng
IMG_0027.dng
folder images_group10
IMG_0049.dng
IMG_0050.dng
IMG_0051.dng
This is the script I have thus far, but I know there are errors and I can't get it to work the way I want:
-- begin script
tell application "Finder"
          -- Select all files in the folder selected from dialog box
                      set theFiles to files of folder (choose folder)
          -- Prepare to select groups of 3 files (1-3, 4-6, 7-9, etc.)
          set theInterval to 3
          -- Initialize the number of the group of 3 images
                      set groupNumber to 0
          -- Display dialog requesting location to create new folder
          set p to path to desktop
          -- Create new container folder in specified location
                      make new folder at p with properties {name:"seq_groups"}
          -- Loop through groups of 3 files, each time creating a container folder
          -- and copying the 3 files to that container folder
                      repeat with i from 1 to (count theFiles) by theInterval
                                        set groupNumber to groupNumber + 1
                                        set itemsToCopy to null
                                        set itemsToCopy to item i of theFiles
                                        set itemsToCopy to itemsToCopy & item i+1 of theFiles
                                        set itemsToCopy to itemsToCopy & item i+2 of theFiles
                                        copy files itemsToCopy to folder ____
          end repeat
          -- Display message box confirming success
end tell
You can see from the comments that I'd like to have it flow as follows:
User either drags a folder onto the script, selects from the Services menu, or runs the applet to get a dialog box to choose folder
Applet runs on all images within the folder and copies, rather than moves (just in case something goes terribly wrong)
Applet confirms it is finished
Any help would be greatly appreciated. Thanks again!

Thanks, I played with it a bit more and this is the final result after more googling:
tell application "Finder"
          set source_folder to (choose folder with prompt "Choose Source Folder")
          set container_folder to (choose folder with prompt "Choose Destination Folder")
          set the_count to 1
  sort files in folder source_folder by name
          repeat ((count files in folder source_folder)) div 3 times
  make folder at folder container_folder with properties {name:"images_group" & the_count}
                    set the dest_folder to folder ("images_group" & the_count) of container_folder as alias
  duplicate files ((the_count * 3) - 2) thru (the_count * 3) of folder source_folder to folder dest_folder
                    set the_count to the_count + 1
          end repeat
end tell
The only problem I continue to have is that it's not going by the "Finder order" of image sequence. Because each group of 3 is a different "scene" I need to make sure that wherever the file numbering sequence starts, it goes in order. Ideally, I'd like for it to read the metadata from the image files (they're all in DNG) and sort by capture time, but that seems a bit outside the scope of AppleScript's capabilities. Thank you again for your help!

Similar Messages

  • Selecting the first file from a group of opened files in Photoshop

    Hi, I've been digitizing microfiche with 200 or so pages photographed onto one image file, laid out in a grid pattern. I've been using actions in Photoshop to cut out one page, create a new file in Photoshop from that page, then return to the first, master file and do it again with the next page in the series. So when it is complete I have each individual page as an individual image file which I then save with a batch process. I've been doing this for a while and have managed to make it work but I always run into the problem, when creating this action again, of getting Photoshop to select that first master file each time instead of selecting just the previous file. I know I can get it to select the previous file, or the previous file -1, -2, -3, etc. I've somehow been able to get this to work in the past by creating an action that selects a large enough group back, like previous file -19 or something, and through some bug or sheer luck it has worked and will always select that first file. But it doesn't always work and it always takes some frustration to luck into it when it does. Now I can't seem to get it to work at all. Is there a straightforward way I can simply tell it to select the first file everytime? If not, does anyone know how or why the method I used previously sometimes works and sometimes doesn't, and how I can make it work again? I'm using PS CS5 in Windows 7. Thanks!

    Just put this code on a file and put that 'namedfile.jsx' inside the scripts folder on photoshop.
    Open or re-open photoshop to load the script and create an action linked to a shortcut selected by you and save this script going to File>Scripts>namedfile.jsx
    It is just to press the shortcut key and the active image go back to the image opened before.
    When it is the first one it runs the script the same but it remains there.
    Here is the script:
    // Go back to the previous opened image
    #target photoshop
    // Go back to the previous opened image (not the previous viewed) . If it is the first, it remain there.
    if(documents.length>0) {
        var thisIndexImage = getActiveDocumentIndex();
        var theDocs = app.documents;
        if ( thisIndexImage != 0 ) {
            var flatAnterior = theDocs[thisIndexImage - 1];
            } else {
            var flatAnterior = theDocs[0];
        app.activeDocument = flatAnterior;
    } else {
        alert ("You must have opened images to run this script.")
    // Get the active document number - the number of opening order
    function getActiveDocumentIndex(){
         var ref = new ActionReference();
         ref.putEnumerated( charIDToTypeID("Dcmn"), charIDToTypeID("Ordn"), charIDToTypeID("Trgt") );
         return desc = executeActionGet(ref).getInteger(stringIDToTypeID('itemIndex'))-1;
    If you want to go directly to the first of all the images (in opening order) it is simpler:
    Just create this script:
    var first = app.documents[0];
    app.activeDocument = flatAnterior;

  • Applescript set selection to list from txt file

    For an AppleScript I am writing, I need to have the program select certain song names in iTunes. Basically, I have a txt file with the song names and I want the AppleScript to select exactly those names. For instance, the txt file looks like
    Track1
    Track2
    Track3
    Track4
    Track5
    with the track names replaced with the actual song names. Every track in seperated by one return, although I can reformat the file to add more returns if necessary. I would like to write something like:
    tell application "iTunes"
         set sel to --every track in the txt file--
         ---rest of my code---
    end tell
    I hope this was clear. Any ideas? Thanks!

    Thanks again DFGray for the comments. 
    After the correlations to find the peak positions, i just take the max value.  And you are right the accuracy is limited by the number of  samples per cycle.  Perhaps it would be clearer if you see the code.
    1) Basically I get a signal on the up and downslope of the sine wave.  On the down slope however the signal is negative, i.e. its is flipped.  So before I shift and average...I 'cut' the waveform into 4 (when cycles per buffer = 2, then I get 4 signals, 2 on the up slope and 2 on down slope) bits.  Counting from one, I flip the even number, cut it, and but an array of waveforms which is then sent to be convolved and shifted.
    2) Array of waveforms are stored to be phased shifted (Convolve and shift vi) and averaged (entire averaging vi which uses the convolve and shift vi as a sub vi). 
    * Phase shifting doesn't work when I cut and put it together (So something is wrong in cut waveform vi) 
    * Also if it isn't too time consuming could you give me an example of interpolating and shifting thing.
    * Also if you have any comments regarding the following VIs please let me know.  
    Thanks 
    Attached is:
    1) Cut waveform vi
    2) Convolve and shift
    3) Entire averaging 
    Attachments:
    SubVICutWaveforms.vi ‏37 KB
    SubVIConvolveShift.vi ‏30 KB
    SubVIEntireAveraging2.vi ‏43 KB

  • Applescript to select specific airport network

    hi all,
    I'd like to write an applescript to select a specific airport network named 'NETGEAR'
    I haven't got much experience with Applescript and I can't get Automator's 'Watch Me Do' to work properly.
    What i'd like done is:
    -select the airport menu (in the menu bar)
    -select the wifi network 'NETGEAR'
    using automator and applescript editor, I've got the following scritpt:
    on run {input, parameters}
        -- Click the “AirPort Menu Extra” menu bar item.
        delay 1.664016
        set timeoutSeconds to 2.0
        set uiScript to "click menu bar item 6 of menu bar 1 of application process \"SystemUIServer\""
        my doWithTimeout(uiScript, timeoutSeconds)
        return input
        -- NETGEAR
        delay 0.882737
        set timeoutSeconds to 2.0
        set uiScript to "click menu item \"NETGEAR\" of menu 1 of menu bar item 6 of menu bar 1 of application process \"SystemUIServer\""
        my doWithTimeout(uiScript, timeoutSeconds)
        return input
    end run
    however, this returns the dialogue: 'AppleScript Error (null)'. So clearly something isn't right.
    I'm sure that whatever mistakes I'm making are pretty obvious to someone who's more familiar with scripting.

    I am so sorry to bother you again. I have another question about how to create a script to change Safari downloaded folder.                                                                            Automatically changing Safari's downloads folder                    
    I have searched a script but it seems to have problem. How should i do?
    -- Set alternative drive name to use as downloads folder here
    set dlFolder to convertHome("/Volumes/Untitled")
    tell application "Finder"
         if exists [POSIX file dlFolder] then
              -- Do Nothing and use the folder
         else
              -- set dlFolder to default home directory
              set dlFolder to (POSIX path of (path to home folder as text)) & "Downloads"
         end if
    end tell
    -- get current path from safari plist
    set currentpath to convertHome(do shell script "defaults read com.apple.Safari DownloadsPath")
    -- change path only if the current setting does not match the input path (there is something to change)
    if (currentpath as text) is not equal to (dlFolder as text) then
         -- if Safari is running, change settings through Safari's preferences
         if appIsRunning("Safari") then
              -- determine the frontmost application to restore when script is done
              set frontApp to path to frontmost application as text
              -- copy the download folder path to the clipboard
              set the clipboard to dlFolder as text
              activate application "Safari"
              tell application "System Events" to tell application process "Safari"
                   -- open the preferences or bring to front (window 1)
                   keystroke "," using {command down}
                   delay 1 -- pauses in window display may result in an error, so we wait a second
                   -- Change to the General tab
                   click button "General" of tool bar 1 of window 1
                   -- Change download location to Other
                   tell pop up button "Save downloaded files to:" of group 1 of group 1 of window"General"
                        click
                        click menu item "Other..." of menu 1 -- three dots is an ellipsis, not three periods
                   end tell
                   -- Open the "go to folder" dialogue box
                   keystroke "g" using {shift down, command down}
                   -- Paste the folder path into the location field
                   tell window "Go To Folder"
                        keystroke "v" using {command down}
                        keystroke return
                   end tell
                   click button "Select" of sheet 1 of window "General"
                   -- close the preferences
                   keystroke "w" using {command down}
              end tell
              -- restore frontmost application after job is complete
              tell application frontApp to activate
         else
              -- if Safari is NOT running, then use the defaults command to change the preferences
              do shell script ("defaults write com.apple.Safari DownloadsPath " & dlFolder)
         end if
    end if
    -- Function to convert home path references to full paths
    on convertHome(currentpath)
         if currentpath contains "~/" then
              set oldDelimiter to AppleScript's text item delimiters
              set AppleScript's text item delimiters to {"~/"}
              set textPath to every text item of currentpath
              set AppleScript's text item delimiters to oldDelimiter
              set currentpath to POSIX path of (path to home folder as text) & item 2 in textPath
         end if
         return currentpath
    end convertHome
    -- Function to check if application "appName" is running (in this case, used for Safari)
    on appIsRunning(appName)
         tell application "System Events" to (name of processes) contains appName
    end appIsRunning

  • Create a group based on file contents

    Hello!
    I'm investigating options to create a dynamic group based on periodic check of file content. I have a Shavlik updater which is patching custom groups based on file contents. I would like to create a dynamic group which should return all Windows Computer
    classes that are found from this file. Anything close to sensible was found at https://www.youtube.com/watch?v=gxASdzHFTOU where author created an attribute of based on "SELECT * FROM CIM_DataFile" and then created a group out from it - but it checks
    file existence, not content, would launch against all Windows Clients (and we have 1000+ of these monitored) - certainly not a valid way.
    Is there any way I could do that in a simple, straightforward way?
    Thanks in advance

    Ok, I got it. Have you tried modifying the group membership with powershell?
    Modifying Explicit Group Membership in SCOM 2012 with PowerShell
    http://blogs.msdn.com/b/rslaten/archive/2013/06/27/modifying-explicit-group-membership-in-scom-2012-with-powershell.aspx
    Automate your group creation with Powershell
    http://blog.coretech.dk/kra/automate-your-group-creation-with-powershell/
    We
    are trying to better understand customer views on social support experience, so your participation in this
    interview project would be greatly appreciated if you have time.
    Thanks for helping make community forums a great place.

  • Creating Target Group from External File

    Hello Experts
    We need to create target group from external file. (That is to say we will have let's say txt file containing BP that belongs to specific target group and we need to assign these BPs to to specific target group in SAP CRM)
    I have searched for it on sdn and found something benefical. I have found BAPI_TARGETGROUP_CREATE, I have checked it but I don't understand how should we use it becuase as far as we understand it just creates target group, we cannot see anything related with Business Partner. How can we relate BPs with the target group we create by this BAPI.
    What should we do, is anyone have previous experience about it? or is there a way to do it without using BAPI.
    thanks it advance
    M.
    Edited by: Mehmet Ergul on Jan 22, 2009 11:19 AM

    Hi,
    You can do this from within the standard Web UI. It's straight out of the box.
    Create a profile set and in there create a target group in the target group assignment block just by entering the description of the target group. Then enter edit mode of this target group and click the button "Import Members". Remeber to mark "Change selected target group" unless you want to create a new target group.
    /Anders

  • IN Premiere Pro CC how can I group copy all files in time line to another part of the time line

    How can I group copy all files from one part of the timeline to another part

    From the Premiere Pro manual (I believe track targeting matters, too.  That is, the targeted tracks only are copied): 
    Copy command enhanced to operate on a range in a sequence
    The existing Copy command (Edit > Copy, Ctrl+C (Windows), Command+C (Mac OS)) is enhanced when used in the Timeline panel. If there are no clips or keyframes selected, and an In Point or Out Point is set, then the range of time between the In point and Out point is copied to the clipboard.

  • Cannot select 'Selected groups' to sync address book contacts to ipad

    Hi,
    After i upgraded to iOS5, I cannot select 'selected groups' to sync address books to ipad. I am syncing via icloud, but there is no option so sync selected groups contacts, nor via itunes for manual sync.
    Can anyone help, please.

    Exported addresses from Address Book to desktop and then deleted all addresses from Address Book.
    Deleted file AddressBook-v22.ab** from Library>Application Support>AddressBook.
    Exited Address Book and iTunes, restarted Address Book and imported addresses from desktop.
    Restarted iTunes and all of the groups were visible in the "Synch Address Book Contacts" window.

  • How to transfer the tables from one file group to another file group in SQL 2008.?

    Hello all,
    I have few issues regarding the transfer of the tables from one file group to another file group  in SQL 2008 and also How can we  backup
    and restore the particular database based on file group level.
    Let’s say I have a tables stored within the different FG. such as
    Tables                                                    
      File group
    Dimension tables                                              
                                                                     Primary
    Fact tables                                               
                                                                              FG1
               FG2…
    zzz_tables                                               
                                                                              DEFAULT_FG    
    dim.table1                                                                                                                          DEFAULT_FG
    dim.table2                                                                                                                          DEFAULT_FG
    Here all I want to transfer the dim.table1 ,dim.table2  from  DEFAULT_FG to the Primary File
    group .So is there simple methods for transfer the dim.table1,2  from one FG to another .I have tried somewhat but I couldn’t get the exact way .So if someone have better idea please share your knowledge that would be really appreciated.
    Secondly after moving those dim.table1 ,dim.table2 from DEFAULT_FG to Primary ,All I want to backup and restore the database only containing  the Primary and FG1,FG2… not
    a DEFAULT_FG.Is it possible or not.?
    Hope to hear from the one who knows better approach for this kind of task .Your simple help will be much appreciated.
    Regards,
    Anil Maharjan

    Well after all my full day research on this topic had paid off, I finally got the solution and am so happy to research on these things. It makes
    us feel really happy after all our research and hard work doesn't goes as waste.
    Finally I got what I am looking for and want to make sure that I am able to transfer the tables from DEFAULT_FG to another FG without tables
    having clustered index on that tables .
    With the help of the link below I finally got my solution where Roberto’s coded store procedure simply works for this.
    Really thanks to him for his great post and thanks to all for your response and your valuable time.
    http://gallery.technet.microsoft.com/scriptcenter/c1da9334-2885-468c-a374-775da60f256f
    Regards,
    Anil Maharjan

  • How to get selected sequence in a file

    Hello,
        I can get the selected sequence file by accessing the RunState.InitialiSelection.SelectedFile property. However, if i want to get the name of the sequence that was selected in this sequence file, then how can i get that?
    Thanks,
    Regards,
    Aparna

    Hello,
       Sorry, i saw this thread a little late. My question is still the same. The solution that you gave actually gives me the display name of the sequence file. But i wanted the name of the sequence that was opened withtin the sequence file. Here is what i have.
    A sequence file named TestExport.seq has two sequences  - MainSequence and SecondSequence. I open up the sequence file and open the SecondSequence in that file. But i dont know how to get this information about the sequence that is selected within the file. I have an external dll, in which i am passing the sequence file name as RunState.InitialSelection.SelectedFile. But i do not know how to get the sequence name that was actually opened in that file. Because i actually want to get the sequence context of the sequence within the file. The code that i have looks like this:
    public ExportDlg(SequenceFile seqFile)
                InitializeComponent();
                SequenceContext seqContext = seqFile.NewEditContext();
                engine = seqContext.Engine;
                object outParam = System.Type.Missing;
                this.seqContext = engine.NewEditContext(seqFile.GetSequence(0).AsPropertyObject(),System.Type.Missing,out outParam);
    seqFile.GetSequence(0) - gives me the context of the first sequence which is MainSequence. But if i have opened the SecondSequence, i need the context for that. And to get this, i need the sequence name "SecondSequence" somehow.
    RunState.InitialState.SelectedSequences is an array of containers. Although i can see the sequence name during executing, i do not know how to get the name of the container my external dll .
    Please help,
    Thanks,
    Regards,
    Aparna

  • Authorization Error while exporting a target group to local file

    Dear All,
    When we tried to export a created target group to local file, system gave an error message: "Authorization required. See SAP Note: 697572".
    In this note, it tells that we should add certain authorization entries into the Java policy file under: \lib\security. It mentioned:
    Authorization              Target name       Action
    RuntimePermission                                modifyThread
    PropertyPermission        user.dir           read
    FilePermission            <<ALL FILES>>   read
    FilePermission            <<ALL FILES>>    write
    RuntimePermission                                  shutdownHooks
    And what we put into the policy file is as below:
         permission java.util.PropertyPermission "user.dir", "read";
         permission java.util.FilePermission "ALL FILES", "read";
         permission java.util.FilePermission "ALL FILES", "write";
         permission java.util.RuntimePermission "modifyThread";
         permission java.util.RuntimePermission "shutdownHooks";
    We are not sure about whether we should put  <<ALL FILES>> or ALL FILES, but tried both way and still didn't work.
    Could you please share your experience on this?
    Thanks!

    Tried again and it worked.

  • Field Selection Group for Batch Management

    Hi All,
    I do not want to make the field mandatory for Raw Material during creation of material master.
    I checked the fileld selection group for MARA-XCHPF for ROH material type, MM01 , it is optional.
    But when i try to create the Material Master for ROH it is showing mandatory field.
    Amit Shah

    Hi,
    Go to the OMS9, here enter the Field sel. group 75 for your MARA-XCHPF, enter and then check the ROH Field refrece, if it shows required then select either Optinal entry or Hide or Display as per the requirement.
    Check and revert.
    Hrishi

  • Using bootcamp was installing windows xp, at the select ntfs or fat format selected "leave the current file system intact." How can that be changed to a correct choice. Mac side opens correctly. Windows shows disk error.

    using bootcamp, was installing windows xp, at the select ntfs or fat format mistakenly selected "leave the current file system intact." How can that be changed to a correct choice. Mac side opens correctly. Windows shows disk error. and doesn't respond to press any key. When looking in the startup disk section, windows on boot camp can be seen, but not selected. (13"MacBook Pro  10.6.8)

    Have a read here http://support.apple.com/kb/TS1722 for solution.
    Stefan

  • When i use view as list in finder and open a folder with many files i cant right click with mouse without selecting or highlighting a file....i just want to right click to paste an item or create a new folder...what can i do?

    When i use view as list in finder and open a folder with many files i cant right click with mouse without selecting or highlighting a file....i just want to right click to paste an item or create a new folder...what can i do?

    Thx for that im gonna try it....but is there a way to do it without using toolbar or cmd-c...? i mean using only the mouse?why does it have to highlight the file even though i click a bit next to it....?using icon view i can right click next to the folder and i wont have a problem but with list view that i prefer using it will highlight the whole row.....and i dont find free space to right click cause i got many files

  • Snow Leopard Finder's Get Info fails to show Owner and Group for some files or folders which reside on a Shared Volume, hosted by G5 Server w/ OS 10.4 - why?

    Frustrations with file permissions abound, as certain co workers are unable to manually determine their level of permission or who to ask to make changes to files and folders belonging to others. Users of Snow Leopard desktop OS get unhelpful feedback via Finder's Get Info, seeing only the permissions listed for "Everyone" and a statement that "You have custom access".  The custom message exists, presumably, because ACL's are employed on the shared volume in an attempt to give managerial control over these volumes to specific users, even if all users can create files and folders on those volumes.
    Shared volumes are partitions of an external RAID which are set up as sharepoints on a G5 tower running Server 10.4.  Other persons in the office, using machines that are running desktop OS 10.5, can correctly see the assigned Owner and Group permissions (although the "custom access" still shows).  This at least lets the 10.5 user know who created a given file or folder, so that they can resolve permissions-restricted issues if they come up (i.e. User A wants to delete file X, but as it was created by User B, A must contact B and have them delete it.  In 10.6 it appears that A cannot determine who B is).
    I know that ACL's are functioning (enabled on the drive) since we have been making use of ACL-granted write privileges for quite a while (and the custom access seems to be evidence too).
    An error I encountered, pertaining to this, is that I used a 10.6 machine to create a working folder, then generated and saved several files in this location.  Expected permissions thus would be Owner = me (i.e. the user I was logged in as), R/W, Group = staff, R only, Everyone = R only.  However, immediately the permissions shown in Finder / Get Info consisted only of Everyone = R only, with no entry for Owner or Group.  Moreover, clicking + to add either an Owner or a Group resulted in error message that I had entered an invalid user or group, even though I typed in correct info (such as trying to add "staff" as a group).

    Frustrations with file permissions abound, as certain co workers are unable to manually determine their level of permission or who to ask to make changes to files and folders belonging to others. Users of Snow Leopard desktop OS get unhelpful feedback via Finder's Get Info, seeing only the permissions listed for "Everyone" and a statement that "You have custom access".  The custom message exists, presumably, because ACL's are employed on the shared volume in an attempt to give managerial control over these volumes to specific users, even if all users can create files and folders on those volumes.
    Shared volumes are partitions of an external RAID which are set up as sharepoints on a G5 tower running Server 10.4.  Other persons in the office, using machines that are running desktop OS 10.5, can correctly see the assigned Owner and Group permissions (although the "custom access" still shows).  This at least lets the 10.5 user know who created a given file or folder, so that they can resolve permissions-restricted issues if they come up (i.e. User A wants to delete file X, but as it was created by User B, A must contact B and have them delete it.  In 10.6 it appears that A cannot determine who B is).
    I know that ACL's are functioning (enabled on the drive) since we have been making use of ACL-granted write privileges for quite a while (and the custom access seems to be evidence too).
    An error I encountered, pertaining to this, is that I used a 10.6 machine to create a working folder, then generated and saved several files in this location.  Expected permissions thus would be Owner = me (i.e. the user I was logged in as), R/W, Group = staff, R only, Everyone = R only.  However, immediately the permissions shown in Finder / Get Info consisted only of Everyone = R only, with no entry for Owner or Group.  Moreover, clicking + to add either an Owner or a Group resulted in error message that I had entered an invalid user or group, even though I typed in correct info (such as trying to add "staff" as a group).

Maybe you are looking for