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.
Similar Messages
-
Drop the files into different directories based on the filename
Hi,
I had a reqiuirement based on the file name, i should drop the files in to different directories.
I can get the filename through variable substitution in receiver file communication channel, now i want to drop the file into different folders based on conditions.
suppose, if the file name is DDDX234
i should do substring of filename0+(4), if the value is L then i should drop in X directory
suppose, if the file name is DDDY234
i should do substring of filename0+(4), if the value is L then i should drop in Y directory.
How can i drop the file into differnent directories based on filename.
Thanks
SrinivasThanks Michal,
I mapped the directory and filename to the target header in the mapping
Filename --> UDF --> Header(target)
and in the receiver channel checked the ASMA and given * in the filename and directory name.
But in runtime iam getting the error as
Attempt to process file failed with com.sap.aii.adapter.file.configuration.DynamicConfigurationException: The Adapter Message Property 'FileName' was configured as mandatory element, but there is no 'DynamicConfiguration' element in the XI Message header
MY UDF is
public String Directory(String a,Container container){
DynamicConfiguration conf = (DynamicConfiguration) container.getTransformationParameters().get(StreamTransformationConstants.DYNAMIC_CONFIGURATION);
DynamicConfigurationKey key = DynamicConfigurationKey.create( "http://sap.com/xi/XI/System/File", "FileName");
DynamicConfigurationKey key1 = DynamicConfigurationKey.create( "http://sap.com/xi/XI/System/File", "Directory");
String FileName = conf.get(key);
FileName = a;
conf.put(key, FileName);
%%%based on filename the directory should change
String Directory = conf.get(key1);
Directory = "/SAPInterface/XI/PPD/DHX/out";
conf.put(key1, Directory);
return "";
Help me in correcting this error.
Thanks
Srinivas -
Script to select files in a folder based on extension
Does anyone have a script that would select files in a folder based on extension, then move the files somewhere else?
Hi Kagey and welcome!
You have to be completely accurate about the path. If your hard disk is called "Macintosh HD", then it's
every file of folder "Macintosh HD:Applications:FileMaker Pro 6 Folder" whose name extension = "tab"
You can generalise this for other users if you can't be sure about the name of their hard disk:
set apps_folder to path to applications folder as string
set fmp_folder to apps_folder & "FileMaker Pro 6 Folder"
tell application "finder" to get every file of folder fmp_folder whose name extension = "tab"
HTH
H
PS - well done in the footy -
Copy a file into multiple folders action
Hello All,
I'm looking for help with a seemingly difficult action; I want to copy a text file into every folder within a location, if its not already there.
I have over 100 projects ready to go out, and need to add a copyright notice .rtf file into each folder. Is there a way I can get Automator to do this? It would save me some time now, and certainly in the future.
Thanks.rajneesh kumar wrote:
-- Ask DBA to grant read , write privileges on this particular directory to your oracle user ie
-- grant execute ON utl_file to your_user;
-- grant read,write on directory john_test_dir to your_user;
-- ALTER SYSTEM SET utl_file_dir = 'e:\jp_test\image_dir' SCOPE=SPFILE;
-- restart the instanceNO! NO! NO!
You should no longer use the utl_file_dir parameter as this has been deprecated by Oracle and replaced with directory objects. Setting the utl_file_dir parameter will leave your file system open to users corrupting files if you are not careful. This parameter should be unset of any value if it has any value set in it and you should set up directory objects instead.
The correct thing to do is to create a directory object e.g.:
CREATE OR REPLACE DIRECTORY mydir AS 'c:\myfiles';Note: This does not create the directory on the file system. You have to do that yourself and ensure that oracle has permission to read/write to that file system directory.
Then, grant permission to the users who require access e.g....
GRANT READ,WRITE ON DIRECTORY mydir TO myuser;Then use that directory object inside your FOPEN statement e.g.
fh := UTL_FILE.FOPEN('MYDIR', 'myfile.txt', 'r');Note: You MUST specify the directory object name in quotes and in UPPER case for this to work as it is a string that is referring to a database object name which will have been stored in uppercase by default. -
Questions re moving files into Events folders
If you move files into an FCP X Events folder, when you open FCP X will it recognize the new files?
Or must FCP X import files into Events folder to recognize and use them?Great, thanks Tom.
there are two situations where I am now 1st going to other folders, then importinging into an FCP X Events folder. This costs me drive space (duplicate files) and time (for importing):
(1) Using Clip Wrap to convert AVCHD files from Sony FS100 cameras to Pro Res 422
(2) Round-tripping from FCP X to DaVinci Resolve, then rendering the graded media files. -
AppleScript Split text file into multiple files
I have large text files that I would like to break up into individual files. They are compilations of articles; I want to create a new file for each article, which begins with:
Document # of #
I don't think any other lines start with "Document" so that might be fine as a delimiter.
Also, it would be great if the new files could be named "LAT_1", "LAT_2", etc.
I found this thread:
AppleScript separating one text file into many at Paragraph break
I tried the second script by twtwtw and changed
set parsingText to "Document"
but got the following error:
error "Can’t get item 2 of {\"LAT 1985-1990 local food copy.txt\"}." number -1728 from item 2 of {"LAT 1985-1990 local food copy.txt"}
I also found this thread but it was too complicated for me to understand. Re: Split a large text file with many entries into separate files
Can anyone help me modify the script? I've been looking at this as well as Unix commands to use in Terminal, but I'm just too much of a beginner.
Any assistance is much appreciated!
TrishaHello
Here's a modified version of the script in
Split a large text file with many entries into separate files
https://discussions.apple.com/thread/5641125?tstart=0
This will split the given text by delimiter line in the form of "Document # of #" and save each chunk of text from one delimiter to the preceding line of the next delimiter in separate file named after LAT_0000.txt, where 0000 is sequential number starting at 0001.
Note that any text before the first delimiter is ignored and not saved in output file. You may select multiple input files. Existing file in the destination folder is overwritten. Input text is assumed to be in UTF-8 and each line is termitated by U+000A LINE FEED.
set ff to choose file with prompt "Choose input file(s)." with multiple selections allowed
set d to choose folder with prompt "Choose destination folder."
set args to ""
repeat with a in {d} & ff
set args to args & " " & a's POSIX path's quoted form
end repeat
do shell script "/usr/bin/perl -CSDA -w <<'EOF' - " & args & "
use strict;
sub usage () {
printf STDERR \"Usage: %s output_directory file [file ...]\\n\", $0;
exit 1;
&usage() unless @ARGV > 1;
my $outdir = shift @ARGV;
unless ( -d $outdir ) {
printf STDERR \"Not a directory: %s\\n\", $outdir;
&usage();
my $i = 0;
my ($n, $n0, $t);
while (<ARGV>) {
if ( /^ \\s* Document \\s+ [0-9]+ \\s+ of \\s+ [0-9]+ .* $/ox ) {
$n = sprintf('LAT_%04d.txt', ++$i); # e.g., LAT_0001.txt
if ( $n0 ) {
open(OUT, '>', \"$outdir/$n0\") or die $!; # overwrite
print OUT $t;
close OUT;
($n0, $t) = ($n, $_);
else {
$t .= $_;
if ( $n0 ) {
open(OUT, '>', \"$outdir/$n0\") or die $!; # overwrite
print OUT $t;
close OUT;
EOF"
Hope this may help,
H -
Saving jpeg and html file into different folders
Hi, all.
I developed a VI that generates, on a timely basis, reports (HTML format) that contain some text, numerical values and graph images (jpeg). The problem is that when it saves a HTML file to a folder, JPEG files are also saved into the same folder.
Is there any way I can save these html and jpeg into different folders?
Or is it even possible to generate html report with some graph images without having to have save jpeg files? (this would be even better).
I included a screen shot of the VI.
Thanks in advance for your help.
Attachments:
screen shot.doc 184 KBThere is currently no way, with the Report Generation VIs, to save the image files for an HTML report to a separate folder. If you think this would be a helpful feature, please submit your request to the Product Suggestion Center, and we will look into possibly including this feature in a future release. For now, the only workaround I can think of would be for you to use the File I/O VIs to manually create another folder and move the image files to it, then use the string manipulation functions to edit the contents of the HTML file to point all image file references to the new location.
As for not generating images, I don't know of an easy way to have an HTML page with images where there are not corresponding image files.
Good luck,
-D
Darren Nattinger, CLA
LabVIEW Artisan and Nugget Penman -
Can't put files into nested folders in dock
Whenever I try to put a file into a folder I have in my dock, it will only let me put it in the first level of the folder. Ideally, I would want the folder to pop open and show the next level of folders so I can navigate through levels of nested folders to put the file in the exact place I want deep within my folder hierarchy. I know I can hold down Control on a folder in the dock to show my nested folders, but how can I drag files into those nested folders? I thought this was supposed to be automatic in Tiger. Please help.
Yes- Easy!
When you have your Creative Media Explorer open and your portable device connected, you will see your Zen V Series Media Explorer in the SOURCE window in the upper LH corner. Click on the "+" in front of the Zen V Series icon and it will display the list of folders on the device.
Right click on the main folder for the category you want to put the sub folder in and you will get a drop down menu.
Select "New folder" and you will get the "New Folder" box asking you what name you want for your new folder. It's that easy. -
Applescript moving different files to different folders
I have 377 files I need to move into 377 different folders. The files have a name like "JustAKid_Basketball-10up 2.pdf" where only the number on the end changes. The folders are named for cities with a number on the front. i.e. "374.SHALLOTTE" I'm trying to build a script that can read the file name and match number to number and then move the file into the matching folder. "JustAKid_Basketball-10up 2.pdf" would go into "2.NASHVILLE." Does that make sense? Any help would be greatly appreciated.
IF window 1 contained just exactly 377 folders and 377 files, AND IF all your files really had the same name (except for the number at the end), for example "JustAKid_Basketball-10up 1.pdf", "JustAKid_Basketball-10up 2.pdf", …, "JustAKid_Basketball-10up 376.pdf", "JustAKid_Basketball-10up 377.pdf", THEN you could try the following script:
tell application "Finder"
set k to 377
repeat until k = 0
move file k of window 1 to folder k of window 1
set k to k - 1
end repeat
end tell -
Picking files from multiple folders based on name send to destination folde
Hi,
I want to pick multiple files from multiple folders with one root folder. Based on file name I want to send it to diffirent folders. No need to go for message mapping. Can anyone suggest me.
Thanks & Regards,
Prasad Kotla.Hi Prasad,
to pick the files from multiple source directory, can use "Advance Selection for Source File" in Sender CC.
If you wand to develop a Scenario without Message mapping, develop a scenario as "Sender as Virtual receiver"
This option is available in Sender agreement, just give the dummy name for Msg Interface and Namespace, Name defined should be same in Rec Agreement.
Develop only: Sende CC, Receiver CC, SA, RA
No need to develop ID and RD as no mapping is involved.
If u want to send the files to different folders of receiver side, just develop the adapter module which changes the directory based on the sender filename.
If the sender and receiver directory is same than check the "adapter specific Msg Attribute" and "directory" checkbox in both the sender and receiver CC. in this case no need to develop Custom module for changing the directory. files will be automatically placed in the path they were picked from sendor directory
appreciate if useful
regards,
chandra shekhar -
Labeling folders based on extension
Is it possible to label a folder based on extension?
For example if I have a folder like this Pictures-WORK / Documents-WORK is it possible to get OS X to label all my folders based on the -WORK ?
Kind regards,
MaximeHi Niel,
Thanks for the reply,
Could you explain a bit more about that script rule?
Kind regards,
Maxime -
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 -
How can I use a custom js file to specify link destinations?
If I use a rectangle to create a button (name "ExitRight"), I specify the button action in a click script. So, to go to a web page using the click script, I enter:
window.location= " window.location="https://www.google.com/";
This works fine and if I look in the edgeAction.js file I find:
//Edge symbol: 'engine_anim'
(function(symbolName) {
Symbol.bindElementAction(compId, symbolName, "${_ExitRight}", "click", function(sym, e) {
// insert code for mouse click here
window.location="https://www.google.com/";
//Edge binding end
})("mySymbol");
//Edge symbol end
Now, what I really want to do is be able to change the destination the button takes me to by using a global variable to specify the destination:
something like...
window location = myDestination;
...where myDestination is a global created in an external custom js document loaded in to the script library
Just putting...
myDestination = "https://www.google.com/";
...into the external js doc doesn't work. So how can I accomplish this?
Peter SmallIt must be summer vacation time. Questions are not being answered and this is the third question that I've had to find out the answer for myself.
The solution I found (from a post by hemanth kumar r https://forums.adobe.com/thread/1479495) was to make variables and functions properties of AdobeEdge.
So in the external .js document a variable is declared and given a value:
AdobeEdge.myVariableName = "The variable value";
To use it in a symbol/element:
alert(AdobeEdge.myVariableName);
And a function is declared:
AdobeEdge.myFunctionName(param){...function code...} //param optional
To call these in a symbol/element:
AdobeEdge.myFunctionName(param);
Peter Small -
How to upload a file into specified location
Hi Frndz..
How to upload a file using File upload feature in web dynpro into our specified location(usr/sap/Images/....),not into workspace r default path in server.
Thanks in Advance
Regards
RajeshHi Rajesh,
Use below code on your "Upload" Action:
try
// Give full path of folder on server where you want to upload the file.
File file = new File("D:\\usr\\sap\\Images\\"+wdContext.currentContextElement().getResource().getResourceName().toString());
// D:\usr\sap\Images folder should present on server
FileOutputStream op = new FileOutputStream(file);
if(wdContext.currentContextElement().getResource()!=null)
text=wdContext.currentContextElement().getResource().read(false);
while((temp=text.read())!=-1)
op.write(temp);
op.flush();
op.close();
catch(Exception e)
wdComponentAPI.getMessageManager().reportSuccess("Error while uploading file : "+e.getMessage());
Thanks
Sandy -
I cannot figure out what causes the erratic misbehavior of sidebar folders. At one point I'll easily drag a file or a folder from the same Finder window into a Sidebar folder, but moments later the sidebar folders simply won't spring open. But a few minutes later they will.
Anyone got a tip?
NB: I had this same misbehavior before I completely rebuilt my HD - I even zeroed to write over bad blocks, reinstalled OS & updated from Apple, gradually added my 3rd party apps by reinstalling each of them (whew!). I had figured that and some other (minor) glitchy behaviors were too little free space, bad block, some directory corruption, etc.Depending on the file, it may just take a minute to decide.
Ray
Maybe you are looking for
-
Time Machine can see my old backups, but not open them
I have been using Time Machine with a Time Capsule (1TB) since last June (on this machine) - quite a few backups in there. Last night when I went to backup, first time in a few days, it said the machine had never been backed up and started the prepar
-
I'm running 10.4.7 right now, I'm thinking I'm finally going to update to 10.4.8 or whatever. How should I go about this? I have 11 updates right now, most of them software updates, two of them firmware updates, and one of them the update from 10.4.7
-
Why does home sharing on my ATV disconnect?
I use my ATV Gen 2 about once a week. When I turn it on and go to the Computers menu, I get a message telling me to turn on home sharing on my computer. But home sharing is on already on both my iMac and my ATV. I have to turn it off and turn it back
-
Safari 6.0.5 crash on startup
can you help me please?! Process: Safari [4956] Path: /Applications/Safari.app/Contents/MacOS/Safari Identifier: com.apple.Safari Version: 6.0.5 (8536.30.1) Build Info: WebBrowser-7536030001000000~6 Code Type: X86-64 (Native) Paren
-
Differencial backup, Log backup and restore
Hi Team, A scenario: If I have backups as below. FullBackup1 LogBackup1 LogBackup2 DiffBackup1 LogBackup3 LogBackup4 If our database crash after logBackup4, Is it really required the DiffBackup1 to recover the db? or will it be possible to recover us