How to alter 'add to file names' script?

I'm working on some stuff that I need to get done today, and it dawned on me that I could save a lot of time if I had a certain script perform a simple task for me. Unfortunately I haven't been able to get one to work right. I just want to be able to add the same thing onto the end of a file name... For instance, 01.jpg would become 01x.jpg, 02.jpg becomes 02x.jpg and so on. The basic 'Add to File Names' script will almost work, but it adds to the front of the name, not the back. Does anyone know how I could alter the lines in that script to get it to do what I want?
Thanks for any help,
Dave

01. Under 'Alternative 01:', the line ...
No error checking for folders is included. Such is an exercise for the student.
... should have been ...
--No error checking for folders is included. Such is an exercise for the student.
02. The error message ...
"System Events got an Error: NSCannotCreateScriptCommandError".
Hmmm, those replying are using MacOS X 10.4.x, and you are using MacOS X 10.2.x. Others, with Macs running MacOS X 10.2.x and using AppleScript code from MacOS X 10.3.x and later, do at times experience 'NSCannotCreateScriptCommandError' error messages.
In the code below, 'System Events' was replaced with 'Finder'. Some additional editing was performed, where required.
Alternative 01:
property tAddition : "x" -- The charcter or string to append to the files' name.
tell application "Finder"
set tSelection to selection
--No error checking for folders is included. Such is an exercise for the student.
repeat with i in tSelection -- Cycle through the provided files.
set {displayed_name, name_Extension} to {displayed name of (i as alias), name extension of (i as alias)}
if ((displayed_name ends with name_Extension) and ((count name_Extension) > 0)) then
-- Handle file names which include a name extension.
set (name of i) to ((get (characters 1 through ((count displayed_name) - (count name_Extension) - 1) of displayed_name) as string) & tAddition & "." & name_Extension)
else
set (name of i) to (displayed_name & tAddition) -- Handle file names without a name extension.
end if
end repeat
end tell
Save the AppleScript code as a script.
Move file (or a copy or alias of the file) to the '~/Library/Scripts/' folder.
Select files to be processed, in 'Finder'.
Select the script, via the 'Script menu'.
Alternative 02:
property tAddition : "x" -- The charcter or string to append to the files' name.
on run {} -- User double-click on the applet.
display dialog "Drag file(s) onto applet for processing."
end run
on open selected_Items -- User dragged items onto applet.
my handleitems(selectedItems) -- Processed items dragged onto applet.
end open
on handleitems(localItems)
-- No error checking for folders is included. Such is an exercise for the student.
tell application "Finder"
repeat with i in local_Items -- Cycle through the provided files.
set {displayed_name, name_Extension} to {displayed name of i, name extension of i}
if ((displayed_name ends with name_Extension) and ((count name_Extension) > 0)) then
-- Handle file names which include a name extension.
set (name of i) to ((get (characters 1 through ((count displayed_name) - (count name_Extension) - 1) of displayed_name) as string) & tAddition & "." & name_Extension)
else
set (name of i) to (displayed_name & tAddition) -- Handle file names without a name extension.
end if
end repeat
end tell
end handle_items
Save the AppleScript code as an applet (application).
Drag files to be processed, onto the applet, in 'Finder'.

Similar Messages

  • How can i add a file name(the text of the file name) as a child node to existing node in a treeView1 ?

    bool exists = false;
    TreeNode newNodeParsed = null;
    TreeNode rootNode = treeViewMS1.Nodes[0];
    TreeNode nextNode = rootNode;
    string f = Path.GetFileName(txtUploadFile.Text);
    TreeNode subnode = new TreeNode(txtDir.Text);
    TreeNode filename = new TreeNode(f);
    if (!txtDir.Text.Contains("/"))
    foreach (TreeNode node in rootNode.Nodes)
    if (node.Text == txtDir.Text)
    exists = true;
    break;
    if (exists == true)
    subnode.Nodes.Add(f);
    else
    rootNode.Nodes.Add(subnode);
    subnode.Nodes.Add(f);
    The rootNode is the root directory in the treeView1
    subnode is a node inside the root. For example the subnode name is manuelisback
    I'm checking if the subnode exist i want to add the file for example (lightning1.jpg) to be under subnode.
    If the subnode is not existing add the subnode to the root and then add the file name lightning1.jpg under the subnode.
    But the file name is never added under the subnode:
    I added manualy the lightning1.jpg under test.
    But the lightning1.jpg also should be added to be under manuelisback. There should be two lightning1.jpg here.
    One under manuelisback and one under test. The one under test i added manualy from my ftp server.
    But the one i want to be under manuelisback i'm trying to add from my program and it dosen't add it to there.
    And when i'm using a breakpoint i see on subnode the text manuelisback and i see on f the text lightning1.jpg

    If I understand your question correctly, you might want to try changing:
    if (!txtDir.Text.Contains("/"))
    foreach (TreeNode node in rootNode.Nodes)
    if (node.Text == txtDir.Text)
    exists = true;
    break;
    if (exists == true)
    subnode.Nodes.Add(f);
    else
    rootNode.Nodes.Add(subnode);
    subnode.Nodes.Add(f);
    to something like:
    if (!txtDir.Text.Contains("/"))
    foreach (TreeNode node in rootNode.Nodes)
    if (node.Text == txtDir.Text)
    subnode = node;
    exists = true;
    break;
    if (exists == true)
    subnode.Nodes.Add(f);
    else
    rootNode.Nodes.Add(subnode);
    subnode.Nodes.Add(f);
    rootNode.Nodes.Add(f);
    It would be greatly appreciated if you would mark any helpful entries as helpful and if the entry answers your question, please mark it with the Answer link.

  • How do you add the files name to images within a PDF

    I have been searching the web trying to find an answer to this question, I am not sure what the proper term is called, but I refer to it as a 'coded pdf'. Hopefully someone knows what I am talking about and can help me find an answer!
    The end product is a coded PDF that has the file name of all the images lableled on top the image. For example, a product brochure that has 500 images, all of them would be 'coded' with their file name, to find easy in source files. - Is this an export option in InDesign, or an option somewhere in Acrobat?
    Thank you in advance for any help.
    -Melissa

    No, Melissa's asking for a filename that's searchable - text made of pixels is no use.
    Acrobat cannot apply the original image filenames after the PDF has been created as it can't read the information from anywhere. You have two options, both in InDesign:
    use smart captions to add the name of the file in a visible format beside each image.
    use accessibility tagging and place the image filename in the ALT TEXT field, then export the PDF with tags enabled (the filename will not be visible on the page but will show if you hover your mouse over the image).

  • Add file name script not working in CS3

    I have this wonderful script (written by Brian Price) back in 2004 for PS7 that adds the file name to an image ( I use it for adding file names to small images to be used in a slideshow). It works great ion Photoshop CS, but when I try to use it as part of a batch action in CS3 it stalls on line 9. OIt works fine when run on just one image in CS3 . . . it just stalls when run as part of a batch action!
    Any help GREATLY appreciated!
    Many Thanks,
    Peter Thompson
    [email protected]
    www.photohawaii.com
    Here's the script:
    // this script is a variation of the script addTimeStamp.js that is installed with PS7
    //Copyright 2002-2003. Adobe Systems, Incorporated. All rights reserved.
    //All amendments Copyright Brian Price 2004 ([email protected])
    //Check if a document is open
    if ( documents.length > 0 )
    var originalRulerUnits = preferences.rulerUnits;
    preferences.rulerUnits = Units.PERCENT;
    try
    var docRef = activeDocument;
    // Create a text layer at the front
    var myLayerRef = docRef.artLayers.add();
    myLayerRef.kind = LayerKind.TEXT;
    myLayerRef.name = "Filename";
    var myTextRef = myLayerRef.textItem;
    //Set your parameters below this line
    //If you wish to show the file extension, change the n to y in the line below, if not use n.
    var ShowExtension = "n";
    // Insert any text to appear before the filename, such as your name and copyright info between the quotes.
    //If you do not want extra text, delete between the quotes (but leave the quotes in).
    var TextBefore = "";
    // Insert any text to appear after the filename between the quotes.
    //If you do not want extra text, delete between the quotes (but leave the quotes in).
    var TextAfter = "";
    // Set font size in Points
    myTextRef.size = 30;
    //Set font - use GetFontName.js to get exact name
    myTextRef.font = "ComicSansMS";
    //Set text colour in RGB values
    var newColor = new SolidColor();
    newColor.rgb.red = 255;
    newColor.rgb.green = 255;
    newColor.rgb.blue = 0;
    myTextRef.color = newColor;
    // Set the position of the text - percentages from left first, then from top.
    myTextRef.position = new Array( 5, 94);
    // Set the Blend Mode of the Text Layer. The name must be in CAPITALS - ie change NORMAL to DIFFERENCE.
    myLayerRef.blendMode = BlendMode.NORMAL;
    // select opacity in percentage
    myLayerRef.opacity = 100;
    // The following code strips the extension and writes tha text layer. fname = file name only
    di=(docRef.name).indexOf(".");
    fname = (docRef.name).substr(0, di);
    //use extension if set
    if ( ShowExtension == "y" )
    fname = docRef.name
    myTextRef.contents = TextBefore + " " + fname + " " + TextAfter;
    catch( e )
    // An error occurred. Restore ruler units, then propagate the error back
    // to the user
    preferences.rulerUnits = originalRulerUnits;
    throw e;
    // Everything went Ok. Restore ruler units
    preferences.rulerUnits = originalRulerUnits;
    else
    alert( "You must have a document open to add the filename!" );

    I have this wonderful script (written by Brian Price) back in 2004 for PS7 that adds the file name to an image ( I use it for adding file names to small images to be used in a slideshow). It works great ion Photoshop CS, but when I try to use it as part of a batch action in CS3 it stalls on line 9. OIt works fine when run on just one image in CS3 . . . it just stalls when run as part of a batch action!
    Any help GREATLY appreciated!
    Many Thanks,
    Peter Thompson
    [email protected]
    www.photohawaii.com
    Here's the script:
    // this script is a variation of the script addTimeStamp.js that is installed with PS7
    //Copyright 2002-2003. Adobe Systems, Incorporated. All rights reserved.
    //All amendments Copyright Brian Price 2004 ([email protected])
    //Check if a document is open
    if ( documents.length > 0 )
    var originalRulerUnits = preferences.rulerUnits;
    preferences.rulerUnits = Units.PERCENT;
    try
    var docRef = activeDocument;
    // Create a text layer at the front
    var myLayerRef = docRef.artLayers.add();
    myLayerRef.kind = LayerKind.TEXT;
    myLayerRef.name = "Filename";
    var myTextRef = myLayerRef.textItem;
    //Set your parameters below this line
    //If you wish to show the file extension, change the n to y in the line below, if not use n.
    var ShowExtension = "n";
    // Insert any text to appear before the filename, such as your name and copyright info between the quotes.
    //If you do not want extra text, delete between the quotes (but leave the quotes in).
    var TextBefore = "";
    // Insert any text to appear after the filename between the quotes.
    //If you do not want extra text, delete between the quotes (but leave the quotes in).
    var TextAfter = "";
    // Set font size in Points
    myTextRef.size = 30;
    //Set font - use GetFontName.js to get exact name
    myTextRef.font = "ComicSansMS";
    //Set text colour in RGB values
    var newColor = new SolidColor();
    newColor.rgb.red = 255;
    newColor.rgb.green = 255;
    newColor.rgb.blue = 0;
    myTextRef.color = newColor;
    // Set the position of the text - percentages from left first, then from top.
    myTextRef.position = new Array( 5, 94);
    // Set the Blend Mode of the Text Layer. The name must be in CAPITALS - ie change NORMAL to DIFFERENCE.
    myLayerRef.blendMode = BlendMode.NORMAL;
    // select opacity in percentage
    myLayerRef.opacity = 100;
    // The following code strips the extension and writes tha text layer. fname = file name only
    di=(docRef.name).indexOf(".");
    fname = (docRef.name).substr(0, di);
    //use extension if set
    if ( ShowExtension == "y" )
    fname = docRef.name
    myTextRef.contents = TextBefore + " " + fname + " " + TextAfter;
    catch( e )
    // An error occurred. Restore ruler units, then propagate the error back
    // to the user
    preferences.rulerUnits = originalRulerUnits;
    throw e;
    // Everything went Ok. Restore ruler units
    preferences.rulerUnits = originalRulerUnits;
    else
    alert( "You must have a document open to add the filename!" );

  • AppleScript "Add to File Names.scpt" (in Finder Scripts) adds "Prefix" to end of files rather than adding actual prefix?

    This may be a quirk with my setup, but when the file "Add to File Names.scpt" runs in Mavericks "Prefix" is appended to the end of filenames rather than the term I would like to be added as a prefix...unsure if this can be reproduced on other comptuers? Similarly, as a test, if a term is intended to be added as a suffix to a file name then "Suffix" is appended to the end of a file name - rather than the term.
    If this is a bug is there a fix?
    Thanks

    apparently this is a bug with a workaround as described here:
    https://discussions.apple.com/message/24085265#24085265

  • How can I assign image file name from Main() class

    I am trying to create library class which will be accessed and used by different applications (with different image files to be assigned). So, what image file to call should be determined by and in the Main class.
    Here is the Main class
    import org.me.lib.MyJNIWindowClass;
    public class Main {
    public Main() {
    public static void main(String[] args) {
    MyJNIWindowClass mw = new MyJNIWindowClass();
    mw.s = "clock.gif";
    And here is the library class
    package org.me.lib;
    public class MyJNIWindowClass {
    public String s;
    ImageIcon image = new ImageIcon("C:/Documents and Settings/Administrator/Desktop/" + s);
    public MyJNIWindowClass() {
    JLabel jl = new JLabel(image);
    JFrame jf = new JFrame();
    jf.add(jl);
    jf.setVisible(true);
    jf.pack();
    I do understand that when I am making reference from main() method to MyJNIWindowClass() s first initialized to null and that is why clock could not be seen but how can I assign image file name from Main() class for library class without creating reference to Main() from MyJNIWindowClass()? As I said, I want this library class being accessed from different applications (means different Main() classes).
    Thank you.

    Your problem is one of timing. Consider this simple example.
    public class Example {
        public String s;
        private String message = "Hello, " + s;
        public String toString() {
            return message;
        public static void main(String[] args) {
            Example ex = new Example();
            ex.s = "world";
            System.out.println(ex.toString());
    }When this code is executed, the following happens in order:
    1. new Example() is executed, causing an object to constructed. In particular:
    2. field s is given value null (since no value is explicitly assigned.
    3. field message is given value "Hello, null"
    4. Back in method main, field s is now given value "world", but that
    doesn't change message.
    5. Finally, "Hello, null" is output.
    The following fixes the above example:
    public class Example {
        private String message;
        public Example(String name) {
            message = "Hello, " + name;
        public String toString() {
            return message;
        public static void main(String[] args) {
            Example ex = new Example("world");
            System.out.println(ex.toString());
    }

  • How do I add a "file folder" to my TC so that I can save files directly to the TC?

    I am trying to figure out how I can add a "File Folder" to my TC so that I can save files directly to it? The only folder it displays is "Data" which is where my bac ups save...

    Double click on the "Data" folder in the Finder under the SHARED heading, and then click the gear icon at the top of the window and select New Folder.
    You can name this folder anything you wish and also create as many folders as you wish.
    If you are also using the Time Capsule drive for Time Machine backups, it is not really recommended that you "mix" regular files with Time Machine backups because there will be a struggle for space on the drive at some point.
    If you have plenty of free space on the Time Capsule drive, you may be OK with keeping a portion dedicated for regular files.

  • Re Trim file name scripts in SL

    Below is a frozen, unanswered conversation regarding the missing finder scripts in SL. Luckily, I make a complete backup before converting, so I still have all the old Leopard scripts. Norwichfan, I feel your pain, and I thought that archiving your thread without an adequate answer was wrong.
    Here's your answer. you can just get a copy of the old finder scripts, put them in /Library/Scripts and they'll show up in your script menu as before. I have zipped up a copy of them and posted them here:
    http://tedward.org/finder_scripts.zip
    norwichfan88
    Posts: 12
    From: Australia
    Registered: Mar 25, 2010
    Trim file name scripts in SL
    Posted: Mar 26, 2010 6:26 PM
    I have recently upgraded to SL and have found that the trim/add to file name applescripts from leopard are missing from my scripts menu.
    Is there a place I can find these for SL?
    MBP mid-2009 Mac OS X (10.6.2)
    Pierre L.
    Posts: 824
    From: Québec
    Registered: Jan 26, 2009
    Re: Trim file name scripts in SL
    Posted: Mar 26, 2010 6:49 PM in response to: norwichfan88
    Solved
    Maybe something similar in this web page?
    15-inch MacBook Pro 2.53 GHz Mac OS X (10.6.2) AirPort Extreme
    norwichfan88
    Posts: 12
    From: Australia
    Registered: Mar 25, 2010
    Re: Trim file name scripts in SL
    Posted: Apr 10, 2010 12:03 AM in response to: Pierre L.
    Thanks for the web page, had a look but not having done any work with applescript or other programming language was a bit over my head.
    I decided to make a temporary solution with and automator action.
    MBP mid-2009 Mac OS X (10.6.2)

    Thanks for the web page, had a look but not having done any work with applescript or other programming language was a bit over my head.
    I decided to make a temporary solution with and automator action.

  • How can I edit the file name of the home page?

    How can I edit the file name of the home page?
    Gr Ammani

    I have a similar issue with regards to the filename...
    When I navigate to my website, it doesnt work unless I actually type the filename at the end of it. Example: type in "www.whitelion.com" (this is my real domain name) and it doesnt work. When I type in "www.whitelion.com/index.html" then it works.
    This is obviously inconvenient because my clients will never know to add the filename to the end of the site.
    Is there any setting or way to get the page to appear by just typing the original domain name without adding the extension?
    Thanks,
    Emelia

  • Edit 'Add to file names'

    I am a complete Newbie to Applescript but I'd like to try and generate a script which does the following:
    - use all selected items in the Finder (image files)
    - show a list with several options for names and events
    - let me select from the list
    - add the name of the choice (eg. "Christmas" or "mom's birthday") to the end of the filename, but before the extension (so that I dont get files with .jpgChristmas as an extension). I would also be ok to first remove or hide the extension to avoid this problem.
    I have been looking at the 'Add to file names' Applescript sample script and I think it should be doable to edit it to do what I mentioned above. I figured I should use
    tell application "Finder" to set ItemList to selection
    to do the first step, namely use only selected items in the finder instead of the whole folder (as the sample script does).
    After this I get quite lost in the documentation... is there anyone that could help me out?
    Thanks a bunch!

    You can get the name and name extension properties of an item and use that to break the name apart, for example:
    <pre style="
    font-family: Monaco, 'Courier New', Courier, monospace;
    font-size: 10px;
    font-weight: normal;
    margin: 0px;
    padding: 5px;
    border: 1px solid #000000;
    width: 720px;
    color: #000000;
    background-color: #DAFFB6;
    overflow: auto;"
    title="this text can be pasted into the Script Editor">
    property theOptions : {"Christmas", "Mom's birthday"}
    property divider : "_" -- a divider between the name and the suffix
    set suffix to (choose from list theOptions with prompt "Choose a name suffix:" with empty selection allowed) as text
    if suffix is in {"", "false"} then return -- nothing added
    tell application "Finder" to repeat with anItem in (get the selection)
    set {theName, theExtension} to {name, name extension} of anItem
    if theExtension is in {missing value, ""} then
    set theExtension to ""
    else
    set theExtension to "." & theExtension
    end if
    set theName to text 1 thru -((count theExtension) + 1) of theName -- the name part
    set name of anItem to theName & divider & suffix & theExtension -- rename
    end repeat
    </pre>

  • How can I add .m4r files (thatI have shortened to 30 seconds or less) to iTunes 11.0.1? I cannot find a ringtones folder in Itunes ans it won't let me drag the files to the sidebar...

    How can I add .m4r files (that I have shortened to 30 seconds or less) to iTunes 11.0.1? I cannot find a ringtones folder in Itunes and it won't let me drag the files to the sidebar...thanks!

    How can I add .m4r files (that I have shortened to 30 seconds or less) to iTunes 11.0.1? I cannot find a ringtones folder in Itunes and it won't let me drag the files to the sidebar...thanks!

  • How do I get the file names on a customized proof sheet?

    How do I get the file names on a customized proof sheet?

    Actually, I really don't know what you say.
    But when you see the properties of a file in Windows, you can see there are two file size. One is called "SIze" and the other one is called "Size on disk".
    Therefore, I would like to know the size on disk but not just the size.

  • How to find out the file name

    Hi,
    In selection screen (parameter) user will give input TXT file from presentation server to upload to SAP. I need to capture the file name only but not the path and need to concatenate with date stamp and need to download error log in XLS file to presentation server.
    How to find out the file name from selection screen?
    I searched SCN threads but not found relavant solution.
    Thanks,
    R Kumar

    Hi
    This code gets only filename from selection screen :
    REPORT x.
    PARAMETERS p_file(100).
    DATA : gv_full_path LIKE  ibipparms-path,
           gv_full_path_string TYPE string,
           gv_filename(100),
           gv_file_ext(3).
    AT SELECTION-SCREEN ON VALUE-REQUEST FOR p_file.
    Ask user to select file with a popup :
      CALL FUNCTION 'F4_FILENAME'
        IMPORTING
          file_name = gv_full_path.
    Get filename from path :
      gv_full_path_string = gv_full_path.
      CALL FUNCTION 'CH_SPLIT_FILENAME'
        EXPORTING
          complete_filename = gv_full_path_string
        IMPORTING
          extension         = gv_file_ext
          name              = gv_filename.
      CONCATENATE gv_filename '.' gv_file_ext INTO gv_filename.
      p_file = gv_filename.
    I hope it helps.

  • How do i sort by (file) name

    How do i sort by file name for an album?  I organize the photos from all different sources.. by filename.. and when i import them i just want them in the right order.  This has to be one of the most basic functions and why was it eliminated from iPhoto?
    Now all i get is "keep sorted by date" check box... (which does not work, some are still not in order)
    Apple:  this minimalist crap is getting old.. THIS IS A desktop PC..not an ipad or iphone.  Put some meat in the menus and stop worrying so much about everything being pretty and streamlined. 
    C'mon!!!.. wasted time

    Now all i get is "keep sorted by date" check box... (which does not work, some are still not in order)
    "Keep sorted by date" can only be toggled on and off for regular albums, not for smart albums.

  • InfoPath 2013: How to find the current file name?

    Hello,
    Is there any way to find the file name in the rule formulas when an existing xml file in a sharepoint form library is being edited in InfoPath? I am looking for a function that returns the current file name that is being edited.
    Thank you,

    Hi,
    According to your post, my understanding is that you want to get the current file name in the InfoPath form.
    Here is a similar thread for you to take a look at:
    http://social.technet.microsoft.com/Forums/en-US/a24f01d5-744c-4b75-b30d-3295311ab054/how-do-i-find-the-file-name-of-the-currently-open-infopath-form?forum=sharepointcustomizationlegacy
    Best Regards
    Dennis Guo
    TechNet Community Support

Maybe you are looking for