How to make applescript to select every 3rd file to move to new folder?
I have an interesting 'problem' I think.
As a result of a time-lapse experminent, I have a folder which holds several thousands of pictures from a fixed point, made over several days & nights.
But there is one issue: the camera made 3 different exposures every 5 seconds.
This resulted in every 3rd picture 'belonging' to each other. So these have to be selected for going in a seperate folder. Menaing: pictures 1 and 4 and 7 and 10 .... they must go in one folder. 2 and 4 and 8 and 11.. in the second folder. Finally 3 and 5 and 9 and 12 in a third folder.
How to do this with software (to avoid injury) because of the thousands of pics.
Is this do-able with applescript? How?
Tnx
Hello
You may try something like the following script.
Main part is written in shell script for performance sake. AppleScript is only used for user interface.
Please see comments in script for its usage and behaviour.
And please test the script first with small subset of your images.
(Since the script will scan the source folder tree for image files, it is good idea not to create destination folders in source folder tree.)
Minimally tested with OSX10.2 at hand but NO WARRANTIES of any kind.
Make sure you have full backup of your images before applying this script.
Hope this may help,
H
image file (jpg) sorter
v0.2
Script will let you choose two folders, i.e. -
a) source folder where images reside (directory tree under the chosen folder is scanned),
b) destination parent folder where three subfolders will be made (named '0', '1', '2').
The file number i is obtained by removing extension and non-digts from file name.
The file with number i (0-based) in source tree will be moved to (i mod 3)'th subfolder in destination.
e.g.,
IMG_1440.JPG -> '0' (i = 1440, i mod 3 = 0)
IMG_1441.JPG -> '1' (i = 1441, i mod 3 = 1)
IMG_1442.JPG -> '2' (i = 1442, i mod 3 = 2)
IMG_1443.JPG -> '0' ...
IMG_9997.JPG -> '1'
IMG_9998.JPG -> '2'
IMG_9999.JPG -> '0'
IMG_0001.JPG -> '1'
IMG_0002.JPG -> '2'
IMG_0003.JPG -> '0'
image file name convention : ZZZZ_9999.jpg
set src to choose folder with prompt "Choose source folder."
set src_ to (src's POSIX path's text 1 thru -2)'s quoted form
set dst to choose folder with prompt "Choose destination parent folder."
set dst_ to (dst's POSIX path's text 1 thru -2)'s quoted form
set sh to "
# source directory
srcdir=" & src_ & ";
# destination directories
dstdir=" & dst_ & ";
dest=("$dstdir"/{0,1,2});
# make destinations
mkdir -p "${dest[@]}";
# let k = number of destination directories
k=${#dest[@]};
# sort files to destinations such that -
# 1) number i is obtained by removing extension and non-digits from file name; and
# 2) file with number i is stored in (i % k)'th destination, where i is zero-based.
# e.g. Given xxxx_9999.jpg, k = 3;
# i = 9999 and the file is sorted to destination 0 (= 9999 mod 3)
find "$srcdir" -type f -iname '*.jpg' -print0 | while read -d $'\0' f;
do
leaf=${f##*/}; # get file name
stem=${leaf%.*}; # remove extension
i=${stem//[^0-9]/}; # remove non-digts from file name
let i=0+10#$i; # to interpret, e.g., 010 as 10, otherwise 010 is treated as octal.
# echo "$i $f ${dest[i % k]}"; # for testing
mv "$f" "${dest[i % k]}"; # move file
done
do shell script sh
display dialog "Done" with icon 1 giving up after 20
Similar Messages
-
Use automator to select every 3rd file to move to new folder?
I have an interesting 'problem' I think.
As a result of a time-lapse experminent, I have a folder which holds several thousands of pictures from a fixed point, made over several days & nights.
But there is one issue: the camera made 3 different exposures every 5 seconds.
This resulted in every 3rd picture 'belonging' to each other. So these have to be selected for going in a seperate folder. Menaing: pictures 1 and 4 and 7 and 10 .... they must go in one folder. 2 and 4 and 8 and 11.. in the second folder. Finally 3 and 5 and 9 and 12 in a third folder.
How to do this with software (to avoid injury) because of the thousands of pics.
Is this do-able with automator? How?
TnxThis has come up a few times, so I tweaked one of my Automator actions a while back to do this. I thought I had uploaded it before, but the latest version of my *Trim Input Items* action is available on my iDisk here. It keeps or trims the input list to the selected number of items from the beginning, end, interval, or random locations. You may need to sort the input file list to get them into the desired order, since the action just works with the items in the list, and doesn't care what they are.
I haven't tested it with large file lists, but an example workflow using my action would be:
1) *Get Specified Finder Items* (or however you want to get the file items)
2) *Set Value of Variable* { Variable: _File List_ }
3) *Trim Input Items* { Keep Interval 3 items, starting from item 1 }
4) *Move Finder Items* { To: _First Location_ } -- move first batch
5) *Get Value of Variable* { Variable: _File List_ } (Ignore Input)
6) *Trim Input Items* { Keep Interval 3 items, starting from item 2 }
7) *Move Finder Items* { To: _Second Location_ } -- move second batch
8) *Get Value of Variable* { Variable: _File List_ } (Ignore Input)
9) *Trim Input Items* { Keep Interval 3 items, starting from item 3 }
10) *Move Finder Items* { To: _Third Location_ } -- move third batch -
How to make Applescript open AI then open file then run ExtendScript then close?
Here's the sample Applescript code I came up with using the scripting guide/reference for CS6 and also doing some online searches:
tell application "Adobe Illustrator"
activate
delay 10
set pfilepath to "/Users/username/Documents/Temp/someFile.ai"
set pfile to POSIX file pfilepath
open pfile as alias without options
delay 10
do javascript "#include '/Users/username/Documents/Temp/someScript.jsx'"
delay 1
quit
end tell
I just want to open the app (sample here for AI but also nice to do same for Photoshop), open a file, then run ExtendScript file against it, then close after processing. With this sample script, all that works is the app launches. No file opened, no script ran, app doesn't close at end. I see no errors pop up nor anything show up in command prompt.
The sample ExtendScript just triggers an alert popup message for testing
Also to note, the Applescript snippet is executed from Python but I believe where/how it's executed shouldn't matter (except maybe where the error messages might show up). Although in worse case, I'll debug/run through the AppleScript editor.
Any tips on what's wrong here? Or does it look technically correct?No, I don't have specific documentation, but you can put together such for Python from bits & pieces here & there. And yes, I made it cross-platform to anticipate Adobe users on both Mac & PC, for which there currently are, though for what we're doing skews towards Windows for now.
For the COM API, follow the VBScript reference and code samples. Just convert the method calls to Python COM. There will be slight syntax differences sometimes (e.g. add "()" to method call for VBScritp subroutines that don't need them, etc.). The scripting guide link below should have code samples for VBScript.
http://wwwimages.adobe.com/content/dam/Adobe/en/devnet/illustrator/sdk/CC2014/Illustrator% 20Scripting%20Reference%20-%20…
http://wwwimages.adobe.com/content/dam/Adobe/en/devnet/illustrator/sdk/CC2014/Illustrator% 20Scripting%20Guide.pdf
For example of Python COM, you can search online, or look at AutoItDriverServer/server.py at master · daluu/AutoItDriverServer · GitHub, which may be bit much/complex for you? For Python COM, you either need ActivePython or regular Python plus Python for Windows Extensions (e.g. pywin32).
For Applescript and Python, this post might be useful: osx - Calling AppleScript from Python without using osascript or appscript? - Stack Overflow
for the rest of the the cross-platform support, it's just generic python to parse command line arguments, etc. You may want to query what platform the script is running under using some standard Python modules (os, system). An example can be found in AutoPyDriverServer/server.py at master · daluu/AutoPyDriverServer · GitHub
Hope that helps. -
How to make a JPanel selectable
When extending a JPanel and overriding the paintComponent() method the custom JPanel can not be selected so that it gets for example KeyEvents.
But if I make the new Class extend a JButton it gets of course selected and able to receive for example KeyEvents.
My question is therefore; what does the JButton implement that a JPanel doesn’t so that a JButton gets selectable? Or in other words; how to make a JPanel selectable?
Aleksander.Try this extended code. Only the first panel added can get the Focus.
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
class Test extends JFrame
public Test()
setLocation(400,300);
setDefaultCloseOperation(EXIT_ON_CLOSE);
JPanel panel1 = new JPanel(new BorderLayout());
JPanel panel2 = new JPanel(new BorderLayout());
ImagePanel imgPanel = new ImagePanel();
panel1.setFocusable(true);
panel2.setFocusable(true);
panel1.setPreferredSize(new Dimension(0, 50));
panel2.setPreferredSize(new Dimension(0, 50));
panel1.setBorder(BorderFactory.createLineBorder(Color.RED, 4));
panel2.setBorder(BorderFactory.createLineBorder(Color.CYAN, 4));
imgPanel.setBorder(BorderFactory.createLineBorder(Color.BLACK, 4));
panel1.add(new JLabel("Panel 1"), BorderLayout.CENTER);
panel2.add(new JLabel("Panel 2"), BorderLayout.CENTER);
getContentPane().add(panel1, BorderLayout.NORTH);
getContentPane().add(panel2, BorderLayout.SOUTH);
getContentPane().add(imgPanel, BorderLayout.CENTER);
pack();
panel1.addKeyListener(new KeyAdapter(){
public void keyPressed(KeyEvent ke){
System.out.println("Panel1");}});
panel2.addKeyListener(new KeyAdapter(){
public void keyPressed(KeyEvent ke){
System.out.println("Panel2");}});
public static void main(String[] args){new Test().setVisible(true);}
class ImagePanel extends JPanel
Image img;
public ImagePanel()
setFocusable(true);
setPreferredSize(new Dimension(400,300));
try{img = javax.imageio.ImageIO.read(new java.net.URL(getClass().getResource("Test.gif"), "Test.gif"));}
catch(Exception e){/*handled in paintComponent()*/}
addKeyListener(new KeyAdapter(){
public void keyPressed(KeyEvent ke){
System.out.println("ImagePanel");}});
public void paintComponent(Graphics g)
if(img != null)
g.drawImage(img, 0,0,this.getWidth(),this.getHeight(),this);
else
g.drawString("This space for rent",50,50);
} -
How to make users to select the date from calendar control only, by my making the date text field read only (don't want to let users type the date) in date time control in external list in sharepoint 2010. I am looking for a solution which can
be done through sharepoint desginer / out of the box.
thanks.Congratulate you got the solution by yourself. I am new to a
WinForms calendar component, I feel so helpless on many problems even I'd read many tutorials. This question on the
calendar date selection did me a great favor. Cheers. -
How to make Label in selection screen?
Hi friends.. can anybody explain how to make labels in selection screens and how to split the selection screen vertically? plz.. Thanks in advance
Arun kumar,
Check this program. you can put labels like this.
REPORT ZVENKAT_TEST1.
SELECTION-SCREEN BEGIN OF BLOCK block.
SELECTION-SCREEN BEGIN OF LINE.
SELECTION-SCREEN COMMENT 1(15) text1.
SELECTION-SCREEN POSITION 17.
PARAMETERS :p_pernr type pa0001-pernr.
SELECTION-SCREEN POSITION 26.
SELECTION-SCREEN COMMENT 27(30) text2.
SELECTION-SCREEN end OF LINE.
SELECTION-SCREEN end OF BLOCK block .
at SELECTION-SCREEN OUTPUT.
text1 = 'Personal number'.
SELECT SINGLE ename FROM pa0001 INTO text2 WHERE pernr = p_pernr.
Regards,
Venkat.O -
Select every nth file from a folder
Hello:
I have a file on my computer that has about 2200 word documents and I need to select every 10th file and place it into another folder. I have zero expierence with this stuff, especially since my imac is my first mac ever; I have had it for about 2 months. Any help would be greatly appreciated !
ThanksThis script
set sourceFolder to choose folder with prompt "Select Source Folder"
set destinationFolder to choose folder with prompt "Select Destination Folder"
set diag to display dialog "Set skip count" default answer "10"
set skipCount to (text returned of diag) as integer
tell application "Finder"
set theFiles to the files of sourceFolder
repeat with n from skipCount to (count of theFiles) by skipCount
duplicate item n of theFiles to folder the destinationFolder
end repeat
end tell
will prompt you for the source and destination folders (the destination folder must exist already) and then prompt for the number of files to skip.
It will duplicate the selected files from the source to the destination. If you do not want the files to remain in the source folder replace duplicate with move in the script.
To make the above into a script select all the text in the box then right (control) click the selection, select Services->Make New AppleScript.
As with all script gotten from the web make sure you test it out on some dummy files first and make sure you have backups of the data you are working on.
regards
Note this will start with the file at skipCount and increment from there. That is with the skipCount set to 10 the first file moved is file number 10 then 20, 30, etc.
Message was edited by: Frank Caggiano -
How to Make Itunes Recognize Foreign Characters in file names?
How to Make Itunes Recognize Foreign Characters in file names?
Any Body, please
DELL Windows XP ProThat's not how it's supposed to work according to this: http://www.griffintechnology.com/support/italkpro/
By default, a playlist will be created in iTunes called "Voice Memos" and those files will be transferred there automatically. The files themselves can be found on your computer in your iTunes Music folder in Unknown Artist > Unknown Album.
It may be worth working through any trouble shooting articles on that site.
Regards,
Colin R. -
How to make iTunes Match not convert my files ALACs in 256 kbps (VBR)? How to get iTunes convert CDs in Apple loselss? The difference between 256 (VBR) and Apple Losless is very clear...
Dear Michael, good day!
1. As per your instruction, I turned off iTM.
Small discrepancy – where are two screens with iTM switch:
-Settings > iTunes & App Store.
-Settings > Music
I switched OFF in both.
NB: I turned device to English for convenience.
2. My next step was Setting > General > Usage – tapped {Music};
{All music} screen appeared; I swiped it and taped Delete.
3. I performed “hard reset” …………………………………..
4. Switched back On iTM
5. Taped Music app on Home screen
iTM has started – (it took 18 minutes to completed, 60 mbps Wi-Fi speed )
Regret to inform… All the same:
Erase and reset to factory default? Or I did smf wrong? -
How to make an openfiledialog? (browse a file and put it in a parameter)
How to make an openfiledialog? (browse a file and put it in a parameter)
Best Regardshi,
check the code below:
FORM sub_gui_download.
* Define local variables
DATA:
lo_fullpath TYPE string,
lo_filename TYPE string,
lo_path TYPE string,
lo_user_action TYPE i,
lo_encoding TYPE abap_encoding.
* Define local constants
CONSTANTS:
lc_encoding(1) TYPE c VALUE 'X',
lc_directory TYPE string VALUE 'D:',
lc_filetype TYPE char10 VALUE 'DAT',
lc_separator TYPE char01 VALUE 'X',
lc_blank TYPE char01 VALUE ''.
* Call method to create dynamic save_path and save_format
CALL METHOD cl_gui_frontend_services=>file_save_dialog
EXPORTING
with_encoding = lc_encoding
initial_directory = lc_directory
CHANGING
filename = lo_filename
path = lo_path
fullpath = lo_fullpath
user_action = lo_user_action
file_encoding = lo_encoding
EXCEPTIONS
cntl_error = 1
error_no_gui = 2
not_supported_by_gui = 3
OTHERS = 4.
IF sy-subrc <> 0.
EXIT.
ENDIF.
* Check user_action
IF lo_user_action <> cl_gui_frontend_services=>action_ok.
EXIT.
ELSE.
* If user_action equals to action_ok, call function module to download datas
* using download table i_dwn_tab
CALL FUNCTION 'GUI_DOWNLOAD'
EXPORTING
filename = lo_fullpath
filetype = lc_filetype
write_field_separator = lc_separator
trunc_trailing_blanks = lc_blank
TABLES
data_tab = i_dwn_tab
EXCEPTIONS
file_write_error = 1
no_batch = 2
gui_refuse_filetransfer = 3
invalid_type = 4
no_authority = 5
unknown_error = 6
header_not_allowed = 7
separator_not_allowed = 8
filesize_not_allowed = 9
header_too_long = 10
dp_error_create = 11
dp_error_send = 12
dp_error_write = 13
unknown_dp_error = 14
access_denied = 15
dp_out_of_memory = 16
disk_full = 17
dp_timeout = 18
file_not_found = 19
dataprovider_exception = 20
control_flush_error = 21
OTHERS = 22.
IF sy-subrc <> 0.
MESSAGE i007.
ENDIF.
ENDIF.
ENDFORM. -
How do you sync only selected songs to your ipod using the new version of itunes?
how do you sync only selected songs to your ipod using the new version of itunes?
Same way you did with the previous versions of iTunes.
To view the iPod in iTunes, Ctrl S to show the sidebar.
Create a playlist, add songs and sync that playlist.
Or drag songs to the iPod in iTunes. -
HT4413 how to upgrade my current OSX, apps, personal files, etc to a new brand SSD
how to upgrade my current OSX, apps, personal files, etc to a new brand SSD
If you have the old hard drive, buy an enclosure, boot your computer off the old hard drive, make a clone of your old hard drive and then copy the clone to the SDD. That will also give you the old hard drive for additional storeage. Other World Computing sells enclosures.
Other World Computing
Clone - Carbon Copy Cloner (Often recommended as it has more features than some others)
Clone – Data Backup
Clone – Deja Vu
Clone - SuperDuper
Clone - Synk
Clone Software – 6 Applications Tested -
HT4623 How can I upload a word or PDF file to the photo album folder on my iphone 5 ?
How can I upload a word or PDF file to the photo album folder on my iphone 5 ?
What is the web site?
-
Yosemite Every time i do login a new folder appear
Every time i do login a new folder appear somewhere on my desktop. I have installed Yosemite
What is the name of this folder? What is in the folder? What Login Items do you have? Does this occur for a different user, e.g., Guest? Does this occur when starting up in Safe Mode?
-
How to get AppleScript to repeat every 10 seconds?
Hi. I created this piece of code using AppleScript Editor on OS X Lion 10.7.3 and I want to make it automatically repeat itself every 10 seconds. The code is supposed to reload the tab which the user is currently on every 10 seconds. I made the reload part but can't figure out how to make it reload every 10 seconds after extensive googling. Here is the code, can someone add the needed code it to make it reload the current page every 10 seconds and reply to me please.
tell application "Safari"
activate
end tell
tell application "System Events"
tell process "Safari"
keystroke "r" using {command down}
end tell
end tellSince you're using UI scripting to emulate a Command-R keypress, Safari has to be frontmost - otherwise the Cmd-R would go to whatever other application was frontmost.
One alternative would be to use a JavaScript to reload the page, rather than UI scripting. For example:
repeat
tell application "Safari"
do JavaScript "location.reload(true)" in document 1
end tell
delay 10
end repeat
There are other JavaScript-based solutions, too, depending on whether you want a simple reload, or re-post form data, etc.
Maybe you are looking for
-
How do I attach a photo in my private message in Facebook using iPad2?
How do I attach a photo to my private messge in Facebook using iPad2? I tried to tap the clip but it didn't respond.
-
New MacMini with SLS as Mail Service
Hi to all, my company needs to replace the older Mail Server (a DP powerPC / macosx server10.4), we're targeting on MacPro 2.66 quadcore but i take a look at MiniMac shipped with SLserver and a double HardDisk and i think it's very interesting. Consi
-
Check when saving Logistics Invoice Verification (MRMBADI_INVOICE_SAVE)
Hi everybody, we have an ECC 6.0. with IS-Retail platform, and we have noticed that during Logistics Invoice Verification process (Tx MIRO), it´s possible to make mistakes by choosing a vendor, then picking an invoice from another vendor, with the pa
-
I have recently downloaded Adope Reader and it has taken over as default from Preview. how do i reset preview as default reader?
-
I converted na PDF to Word & it came back all dis organized