Incrementing folder name script? help...
Here is the thing, im into tethering mode in my nikon camera (Picture talk/transfer protocol) in which it automatically saves every shot into a "hot folder" (~desktop/images) i've got my action to automate 4 pictures to be posted into a 4R size contact sheet, saved as jpeg, and closes the window. though the hard part is, i can't figure out how to automatically script it so that after saving and closing the contact sheet, all of the four raw jpg shots + the newly saved contact_sheet.jpg file would be foldered into a subfolder (inside ~desktop/images) which generates a unique/incrementing folder names everytime. And so, i could continue shooting, and every after 4 shots, i could use my action+ the given script so it automatically does the foldering for me. Below are some examples of what's inside the "image folder" looks like.
above is the ïmage folder before the script should work
above is how the script should work, then after, if another 4 shot has been taken, i could execute the action to make and save the contact sheet and hopefully, if i would use the script again, it would put these five new *.jpg files to a incremented folder name like "Contact (1)" then for the next batch "Contact (2)"... and so on...
Can anyone help me please? Tnx!
I think creating that folder comes close to this, with a few adjustments. I really understand a few in scripting and so I hope someone could help out..
function createFolder(file) {
var parentFolder = file.parent;
var saveFolder = new Folder( parentFolder + '/' + file.name.substring( 0, 8 ) );
if( !saveFolder.exists ) saveFolder.create();
var saveFile = new File( saveFolder + '/' + file.name);
if( file.copy( saveFile ) ) file.remove();
function main() {
var folder = new Folder("~/Desktop/images");
var files = folder.getFiles();
for (var i = 0; i < files.length; i++) {
var f = files[i];
if (f instanceof File) {
createFolder(f);
main();
Similar Messages
-
I am missing the script Add to Folder Names. I still have the alias, but the script is missing. Any sources for this script?
Hi Lannis, here it is...
Add Prefix-Suffix to Fldr Names
Copyright © 2001 Apple Computer, Inc.
You may incorporate this Apple sample code into your program(s) without
restriction. This Apple sample code has been provided "AS IS" and the
responsibility for its operation is yours. You are not permitted to
redistribute this Apple sample code as "Apple sample code" after having
made changes. If you're going to redistribute the code, we require
that you make it clear that the code was descended from Apple sample
code, but that you've made changes.
--set the source_folder to (choose folder with prompt "Pick the folder containing the folders to rename:")
try
tell application "Finder" to set the source_folder to (folder of the front window) as alias
on error -- no open folder windows
set the source_folder to path to desktop folder as alias
end try
set the prefix_or_suffix to ""
repeat
display dialog "Enter the prefix or suffix to use:" default answer the prefix_or_suffix buttons {"Cancel", "Prefix", "Suffix"}
copy the result as list to {the prefix_or_suffix, the button_pressed}
if the prefix_or_suffix is not "" then exit repeat
end repeat
set the item_list to list folder source_folder without invisibles
set source_folder to source_folder as string
repeat with i from 1 to number of items in the item_list
set this_item to item i of the item_list
set this_item to (source_folder & this_item) as alias
set this_info to info for this_item
set the current_name to the name of this_info
if folder of this_info is true then
if the button_pressed is "Prefix" then
set the new_file_name to the (the prefix_or_suffix & the current_name) as string
else
set the new_file_name to the (the current_name & the prefix_or_suffix) as string
end if
my set_item_name(this_item, the new_file_name)
end if
end repeat
beep 2
on set_item_name(this_item, new_item_name)
tell application "Finder"
--activate
set the parent_container_path to (the container of this_item) as text
if not (exists item (the parent_container_path & new_item_name)) then
try
set the name of this_item to new_item_name
on error the error_message number the error_number
if the error_number is -59 then
set the error_message to "This name contains improper characters, such as a colon (:)."
else --the suggested name is too long
set the error_message to error_message -- "The name is more than 31 characters long."
end if
--beep
tell me to display dialog the error_message default answer new_item_name buttons {"Cancel", "Skip", "OK"} default button 3
copy the result as list to {new_item_name, button_pressed}
if the button_pressed is "Skip" then return 0
my set_item_name(this_item, new_item_name)
end try
else --the name already exists
--beep
tell me to display dialog "This name is already taken, please rename." default answer new_item_name buttons {"Cancel", "Skip", "OK"} default button 3
copy the result as list to {new_item_name, button_pressed}
if the button_pressed is "Skip" then return 0
my set_item_name(this_item, new_item_name)
end if
end tell
end set_item_name -
Hi. Macophile just starting to tread the waters of Applescript, trying to use Automator but don't think it will do what I need.
I have many images stored with-in folders that I would like to extrapolate a given number of characters from the folder name and Add Text to the files within those given folders.
Basically...
Folder name is C00100_Descriptive
Files within folder are just Descriptive_01, Descriptive_02
Would like to make all files within a given folder take the first 7 characters from the folder and Add that text to all files and files within subfolders of that folder to make the resulting files shown as...
C00100Descriptive01
C00100Descriptive02
Along with this I would also like to incorporate into the script, an added step to create Thumbnail jpegs of the image files in a Subfolder under C00100_Descriptive folder.
I can see how to do that in automator but not specifying parameters such as taking a certain number of characters from the folder the file resides in and adding that selected text to the files.
Ideally I would like a droplet or something that I could take a bunch of folders and drop them on the droplet to perform these actions.
Any advice, help or guidance would be really helpful! Thanks in advance.Awesome, you're quite welcome, glad to hear it worked for ya!! Here's another version of the script that will rename the thumb files as jpg...
<pre style="width:630px;height:auto;overflow-x:auto;overflow-y:hidden;"
title="Copy this code and paste it into your Script Editor application.">on run
set theItems to choose folder with multiple selections allowed
open (theItems)
end run
on open (itemList)
repeat with anItem in itemList
set theInfo to info for anItem
--VERIFY THAT THE OPENED ITEM IS A FOLDER
if folder of theInfo and not package folder of theInfo then
--SET PATH TO THE FOLDER
set theFolder to POSIX path of anItem
--GET FIRST PART OF FOLDER NAME
set folderNameStart to do shell script "echo " & ¬
quoted form of (name of theInfo) & "|awk -F'_' '{print $1}'"
--GET ALL FILE NAMES
set fileList to list folder anItem without invisibles
--PROCEED IF FOLDER NOT EMPTY
if fileList is not {} then
--SET PATH TO THUMBNAIL FOLDER
set thumbFolder to theFolder & "_thumbs/"
--CREATE FOLDER IF IT DOESN'T ALREADY EXIST
try
do shell script "mkdir " & quoted form of thumbFolder
end try
--PROCESS FILES
repeat with fileName in fileList
--SET PATH TO CURRENT FILE
set oldFile to theFolder & fileName
--PROCEED IF FILE IS NOT A FOLDER
set oldFileInfo to info for POSIX file oldFile
if not folder of oldFileInfo then
--SET NEW FILE AND THUMB FILE PATHS
set newFileName to folderNameStart & "_" & fileName
set newFile to theFolder & newFileName
set theExt to name extension of oldFileInfo
set thumbName to text 1 through -((length of theExt) + 1) of newFileName & "jpg"
set thumbFile to thumbFolder & "thumb_" & thumbName
--RENAME FILE
do shell script "mv " & quoted form of oldFile & space & ¬
quoted form of newFile
--CREATE THUMBNAIL
--REPLACE '128' WITH MAX HEIGHT OR WIDTH OF THUMB
try
do shell script "sips -s format jpeg -s dpiHeight 72 -s dpiWidth 72 -Z 128 " & ¬
quoted form of newFile & " --out " & quoted form of thumbFile
end try
end if
end repeat
end if
end if
end repeat
end open</pre> -
Apple script to replace content in specific folders with folder names in csv
Can anyone please help me with this scenario... It would greatly be appreciated!
1. I have a list in csv containing 3 columns: Column 1 = Folder name • Column 2 = Entry A • Column 3 = Entry B
2. I have 100 folders named the same as Column 1. in each folder there is different files.
This is what I need.
I need the script to to find the folder based upon column 1.
Then the script should search for place holder named "Entry A" and replace it's contents with data from Column 2. There are several files with in the folder that contain place holder "Entry A" so it should replace it all but must remain with in that folder.
Then same for column 3 find place holder named Entry B and replace.
Then it should save all files.
Any help is greatly appreciated! Thank you!Can anyone please help me with this scenario... It would greatly be appreciated!
1. I have a list in csv containing 3 columns: Column 1 = Folder name • Column 2 = Entry A • Column 3 = Entry B
2. I have 100 folders named the same as Column 1. in each folder there is different files.
This is what I need.
I need the script to to find the folder based upon column 1.
Then the script should search for place holder named "Entry A" and replace it's contents with data from Column 2. There are several files with in the folder that contain place holder "Entry A" so it should replace it all but must remain with in that folder.
Then same for column 3 find place holder named Entry B and replace.
Then it should save all files.
Any help is greatly appreciated! Thank you! -
Script Help: Folder Actions - Move files
Hi,
So, I'm having some trouble writing a script for a folder action. I basically want the folder to check the file extension of the files that I add to the folder, and if they are music files (mp3, m4a, m4p), to move those files to a different folder. Additionally, is it possible to also move entire folders containing music files to a different folder, instead of just single files?
Thank you for any help.What is your script doing now (note that a name extension does not include the period delimiter)? You can move entire folders, but your folder action script would only pass the items added to the attached folder, not any folder contents. Your folder action script would need to look into any passed folders if you wanted to move them based on their contents.
-
How to display Contribution Folder Name using Idoc Script
Hi, could ypu please tell me how can we display Contribution Folder name using Idoc script by passing dCollectionID. Appreciate your help on this. Thank you
Regards,
AshokYou should be able to get it directly as dCollectionName, but might have to execute a query to fill in the result set first: select dCollectionName from COLLECTIONS where DCOLLECTIONID = ?
-
Active Content: cannot change Scripts folder name?
Using DW 8.0.2.
After I accept the Active Content workaround to be applied to
my pages, I'd like to change Scripts folder name to "scripts" or
even move the scripts to my "jscript" folder, which already exists.
When I do this DW correctly asks to update the page links, but even
with the correct links the scripts does not run anymore.
It seems to be caused by some JS code included in the
scripts, which points to "Scripts" folder in site root. But I don't
know enough JS to identify and modify this. Any help will be very
welcome.Shouldn't happen. I have moved the AC .....js file many times
to different
folders and if the path is correct, everything works
properly. Can you
please post a link.
You cannot lose until you give up !!!
"Freiberger" <[email protected]> wrote in
message
news:eou61k$enn$[email protected]..
> Using DW 8.0.2.
>
> After I accept the Active Content workaround to be
applied to my pages,
> I'd
> like to change Scripts folder name to "scripts" or even
move the scripts
> to my
> "jscript" folder, which already exists. When I do this
DW correctly asks
> to
> update the page links, but even with the correct links
the scripts does
> not run
> anymore.
>
> It seems to be caused by some JS code included in the
scripts, which
> points to
> "Scripts" folder in site root. But I don't know enough
JS to identify and
> modify this. Any help will be very welcome.
> -
Applescript Help - Add folder name to contents
Hi everyone
I am an Applescript newbie, and I need help!
I have a several folders with 2 jpegs inside them.
All the jpegs are titled "image1.jpg" & "image2.jpg"
I am looking for a quick way to add the folder name as a prefix to each jpeg.
Example:
Folder name - Wellington Boots
Images inside - image1.jpg
The outcome I am looking for is:
Folder name - Wellington Boots
Images inside - Wellington Boots-image1.jpg
This might be really easy to do, but I am struggling to find info on how to do it. Can anyone help?Actually, to make it a bit more robust you can change the script to
tell application "Finder"
repeat with anItem in the input
set prefix to (name of container of anItem) & "-"
set theName to name of anItem
if theName does not start with prefix then -- already prefixed
set name of anItem to prefix & theName
end if
end repeat
end tell
That way it won't add a prefix if there already is one. -
Script or Automator to reorder text in file/folder name
Hello,
Similar to this discussion: https://discussions.apple.com/thread/2632228, I would like to reorder a large number of folder names. Currently, they are set up as follows:
"Name - Year" and would like to change them all to "Year - Name". I have over 200 folders named in this format so I need to find either a way to do this via the automator or via a script. So far I can't find what I need in the Automator. Any ideas? Thank youtry this:
set folderList to choose folder with multiple selections allowed
tell application "System Events"
repeat with thisFolder in folderList
set folderName to name of thisFolder
-- assumes none of the folders have extensions, or anything aside from "Name - Year", and that there are no spaces inside the name or year
-- it can be generalized to deal with that, if needed
set {oldTID, my text item delimiters} to {my text item delimiters, {" ", "-"}}
tell folderName
set {n, d} to {first text item, last text item}
end tell
set my text item delimiters to oldTID
set name of thisFolder to d & " - " & n
end repeat
end tell -
Change Document Library Folder Name from client (JavaScript (JSOM) or Rest)
Hi
According to :
http://social.technet.microsoft.com/Forums/sharepoint/en-US/23441a0d-022a-4d97-8058-b75f32e342d2/rest-api-to-rename-the-folder-move-folder-copy-folder-prog-lang-is-java?forum=sharepointdevelopment
Renaming a folder with Rest is not possible.
and based on:
http://msdn.microsoft.com/en-us/library/office/jj245697(v=office.15).aspx
name property doesn't have any set.
Is it means that renaming a folder is not possible by JSOM or REST?!
RegardsHi,
The following JavaScript Client Object Model code for your reference:
<script type="text/ecmascript">
ExecuteOrDelayUntilScriptLoaded(UpdateListItem, "sp.js");
function UpdateListItem(){
var clientContext;
var oWebsite;
var oList;
clientContext = new SP.ClientContext.get_current();
oWebsite = clientContext.get_web();
oList = oWebsite.get_lists().getByTitle("DocumentLibrary");
oListItem = oList.getItemById(1);
this.oListItem.set_item("FileLeafRef", "Folder Name");
this.oListItem.update();
clientContext.load(this.oListItem);
clientContext.executeQueryAsync(onSuccess, onFailure);
function onSuccess() {
alert('Update succeeded.');
function onFailure(sender, args) {
alert('Request failed. ' + args.get_message() + '\n' + args.get_stackTrace());
</script>
More information:
http://msdn.microsoft.com/en-us/library/office/jj163201(v=office.15).aspx
Thanks,
Dennis Guo
TechNet Community Support
Please remember to mark the replies as answers if they help and unmark them if they provide no help. If you have feedback for TechNet Subscriber Support, contact
[email protected]
Dennis Guo
TechNet Community Support -
Set Folder Name From File Name Inclosed.
Hello scripters,
There has been quite a few topics about setting file names from parent folders. I believe it's possible but not sure how to reverse this process. That is to say set the folder name from a file in the folder. This is what I'm imagining.
I've got a folder. In the folder are 100 folders with the names "untitled folder xxx" In side I've got files that are all named and numbered.
For example,
untitled folder/B-day 001~050.jpg
untitled folder 50/At The Park 001~020.jpg
I would like a script to change the name of the parent folder of the files that it houses.
So untitled folder becomes
B-Day
untitled folder 50 becomes
At The Park
etc…
I think getting the name of the first file (minus the index number) would be easiest.
Any help or futher questions are greatly appreciated.
MaximilianWorking backwards...
Assuming all the files have the same name structure (e.g. end in the format "xxx~xxx.jpg" you can get the base name using:
<pre class=command>set baseName to characters 1 through -13 of filename as text</pre>
This cuts off the last 12 characters of the file name.
Once you have a folder, you can get the names of files in the folder via the Finder. for sanity's sake I'd ask the Finder for the first item, just in case there's more than one file:
<pre class=command>set filname to name of first item of (files of folder theFolder)</pre>
And if all the folders are in one top folder, you can iterate through them like:
<pre class=command>repeat with eachFolder in (every folder of folder topFolder)</pre>
So now, string it all together:
<pre class=command>tell application "Finder" -- we'll use the Finder to do the legwork
set topFolder to (choose folder with prompt "Choose the top level folder" ) -- get the top folder
repeat with eachFolder in (every folder of folder topFolder)
set fileName to name of first file of (files of folder topFolder)
set baseName to characters 1 through -13 of fileName as text
set name of folder eachFolder to baseName
end repeat
end tell</pre>
Note there's no error checking - the script will fail if there are no files in any particular folder, but it should get you going. -
Find the folder name based on the View Name
Hi ,
I need to find out a Folder name based on a View Name . Basically i know the view Name and want to find out the Folder that is created in Discovrer based out of that view.
Does any one know of any EUL table that stores this relationship.
Thanks in advance for your help
SunnyHi,
Your requirement can be fulfilled using the following script:
SELECT bas.ba_name,
bas.ba_id,
obj.obj_name folder,
decode(obj.obj_type,
'COBJ',
'Complex',
'SOBJ',
'Simple',
'CUO',
'Custom',
'Unknown') AS obj_type,
decode(obj.obj_hidden,0,'Bare','Hidden') IS_HIDDEN,
obj.sobj_ext_table folder_source_object
FROM eul10g_us.eul5_ba_obj_links bol,
eul10g_us.eul5_objs ; obj,
eul10g_us.eul5_bas ; bas
WHERE obj.obj_id = bol.bol_obj_id
AND bas.ba_id = bol.bol_ba_id
BUT
As you can see from the SQL, only simple folders are mapped to objects.
This means that if the object is used inside a custom folder or complex folder you will not see it.
Tamir -
Hi All,
I need to retrieve the folder name for where the item is stored to generate a report in following format in csv
File Name Full Path Parent Folder Created By Last Modified By Number of Versions Total Size
My code which gets all other info.
function Get-DocInventory() {
[void][System.Reflection.Assembly]::LoadWithPartialName("Microsoft.SharePoint")
$site=Get-SPSite -Identity "siteURL"
foreach ($web in $site.AllWebs) {
foreach ($list in $web.Lists) {
if ($list.BaseType -ne "DocumentLibrary") {continue}
foreach ($item in $list.Items) {
$data = @{
# "Web Application" = $webApp.ToString();
#"Web" = $web.Url
"Site" = $site.Url
"list" = $list.Title
"Item ID" = $item.ID
"Item URL" = $site.Url+"/"+$item.Url
"Item Name"= $item.File.Name
“Item Versions” = $item.Versions.Count
"Item Created" = $item["Created"]
"Extensions" = $item.name.split(".")[1]
"Item Modified" = $item["Modified"]
"Item Created By" = $item["Author"]
"Last Updated by" = $item["Editor"]
"File Size" = $item.File.Length/1KB
New-Object PSObject -Property $data
$web.Dispose();
$site.Dispose()
#Get-DocInventory | Out-GridView
Get-DocInventory | Export-Csv -NoTypeInformation -Path D:\Scripts\Hemant\inventory.csv
Coukld you please help me get folder name
Thanks BasvaTo get the full Folder URL you could use:
$item.File.ParentFolder.Url
And just for the Folder Name use:
$item.File.ParentFolder.Name -
Automator/Applescript to Rename files when dropped in folder based on parent folder name
When a file is dropped in a folder ( ParentFolder/Folder/File.pdf )
I want to rename the file to ParentFolder_Folder_01.pdf
--Get folder
--Get ParentFolder
--Check for next available number and use it.
If ParentFolder_Folder_01.pdf exists, try _02
I automator, I have chosen folder action
Added 'Get selected finder items'
I have attempted to modify another sript I found here to no avail.
on run {input, parameters}
tell application "Finder"
set theFolder to input as string
set theNameOfFolder to name of folder theFolder
set theFiles to every file in folder theFolder
set theFolders to every folder in folder theFolder
my ProcessFiles(theNameOfFolder, theFiles)
my ProcessFolders(theFolders)
end tell
end run
to ProcessFolders(theFolders)
tell application "Finder"
repeat with thisFolder in theFolders
set theNameOfFolder to name of thisFolder
set theFiles to every file in thisFolder
set theFolders to every folder in thisFolder
my ProcessFiles(theNameOfFolder, theFiles)
my ProcessFolders(thisFolder)
end repeat
end tell
end ProcessFolders
to ProcessFiles(NameOfOuterFolder, theFiles)
tell application "Finder"
repeat with thisFile in theFiles
set theSuffix to my grabSuffixOfFile(name of thisFile)
set name of thisFile to NameOfOuterFolder & "_" & theSuffix
end repeat
end tell
end ProcessFiles
to grabSuffixOfFile(theFile)
set text item delimiters to "_"
return (text item 2 of theFile)
set text item delimiters to ""
end grabSuffixOfFileNormally it is a bad idea to do things with items that are in the attached folder (earlier OS versions will retrigger folder actions when an item is renamed, for example), and you don't need to use a Get Selected Finder Items action since the dropped items are already passed to your workflow (also note that the input items will be a list).
It looks like you are trying to use multiple passes to add on the folder names, but you will have less of a headache if you build the base name and just deal with the number suffix. If I understood your naming scheme correctly, the following script should do the trick - it isn't very fast, but should be OK for a few items at a time.
on run {input, parameters} -- rename input Finder items (aliases) to name of containing folders
set divider to "_" -- the divider character between name pieces
set output to {} -- the result to pass on to the next action
set counter to "01" -- start suffix at one
repeat with anItem in the input -- step through each item in the input
set anItem to contents of anItem -- dereference
tell application "Finder" to if class of item anItem is document file then -- don't mess with folders or applications
set {itemParent, itemExtension} to {container, name extension} of anItem
if itemExtension is not "" then set itemExtension to "." & itemExtension
set grandParentName to name of container of itemParent
set parentName to name of itemParent
set newName to grandParentName & divider & parentName & divider & counter
set documentNames to my getExistingNames(itemParent)
repeat while newName is in documentNames -- increment counter suffix as needed
set counter to text -2 thru -1 of ("0" & (counter + 1))
set newName to grandParentName & divider & parentName & divider & counter
end repeat
set name of anItem to (newName & itemExtension)
set end of output to anItem -- alias still refers to the same file even after renaming
end if
end repeat
return the output
end run
to getExistingNames(someFolder) -- get base document names (no extensions) from a folder
set nameList to {}
tell application "Finder" to repeat with aFile in (get document files of someFolder)
set {fileName, fileExtension} to {name, name extension} of aFile
if fileExtension is not "" then set fileExtension to "." & fileExtension
set fileName to text 1 thru -((count fileExtension) + 1) of fileName -- just the name part
set end of nameList to fileName
end repeat
return nameList
end getExistingNames -
I am in need of a script that will, when prompted to relink broken links, update the path of a changed folder name.
So no matter where the "old file name (X)" is in the link path, it will be updated to "New folder name (Y)"
Also I now very little about scripts so if anyone knows a simplified website that explains how to utilize them that would also be super helpful.
Thanks!Check out the Links section on this page. Probably you you will find something close to your needs.
— Kas
Maybe you are looking for
-
Flicker removal for slideshows
I'm using Premiere Elements 7. I discovered after burning my slideshow that the photos flicker on the TV screen, which looks horrible. The FAQ says you can try and reduce this using flicker removal, but when I right-click on the pictures, "Field Opti
-
How to change the facetime email
how do I change what e-mail address my mac uses for facetime.
-
Hi Experts, I'm new to CRM & ERP thus my question might seem rudimentary to you guys. But that means easy pts to score as well! Business partners and products are types of Business Objects. THe list of B.O. types can be found in SWO1correct? Where (w
-
Hey all, i'm doing a website for a client, and having issues aligning things up properly. I'm still learning CSS, so bear with me! Firstly, check this site out http://www.creativityawaits.com/HowToMakeWelshQuilts/ 1) I'm using 1024x768 and the flash
-
How much video will a 3GS 32gb record (Minutes?)
Just trying to find out how many minutes a 3GS 32gb will record.