Format date from text file

Discussion in 'Mac Programming' started by vloryan, Aug 16, 2014.

  1. vloryan macrumors member

    Joined:
    Jan 11, 2014
    #1
    hi guys,

    i have a date in a txt-file looking like this:

    16.08.2014

    and would like to change this to

    SA.16.08.14

    using apple script. any chance to do this? thanks!
     
  2. JohnsonK macrumors regular

    Joined:
    Mar 6, 2014
    #2
    Definitely doable, yes

    Look into string concatenation
     
  3. vloryan thread starter macrumors member

    Joined:
    Jan 11, 2014
  4. Red Menace macrumors 6502

    Joined:
    May 29, 2011
    Location:
    Littleton, Colorado, USA
    #4
    In AppleScript, the & operator is used to concatenate (join) strings, so by joining the various text elements in the desired sequence you can make your new string - for example:

    Code:
    set originalString to "16.08.2014" -- your example text
    tell originalString to set newString to "SA." & text 1 thru 6 & text 9 thru 10
    return newString
     
  5. vloryan thread starter macrumors member

    Joined:
    Jan 11, 2014
  6. Red Menace macrumors 6502

    Joined:
    May 29, 2011
    Location:
    Littleton, Colorado, USA
    #6
    A single statement is all there is to it. If there is more that you are wanting to do, you will need to specify exactly what it is.
     
  7. lee1210 macrumors 68040

    lee1210

    Joined:
    Jan 10, 2005
    Location:
    Dallas, TX
    #7
    You're not being very specific.

    I think you want a 2 letter day of week prepended, and the year as 2 digit rather than 4.

    http://macscripter.net/viewtopic.php?id=24737
    This page may help? The "euro order" may be tricky.

    -Lee
     
  8. vloryan thread starter macrumors member

    Joined:
    Jan 11, 2014
    #8
    yes, thats what i want, but the date must be read from a date.txt file...
     
  9. Red Menace macrumors 6502

    Joined:
    May 29, 2011
    Location:
    Littleton, Colorado, USA
    #9
    What have you got so far - are you looking for a general-purpose handler to do the date modification, or are you looking for a complete script? Does the date need to be extracted from other text in the text file? Your date is not in a US format - are the dates in the text file the same as the localization you are using?

    You need to be more specific about every detail of what you are trying to do, so we don't have to continue playing this guessing game.
     
  10. hiddenmarkov macrumors 6502a

    Joined:
    Mar 12, 2014
    Location:
    Japan
    #10
    might be of help to the script guru's to show the output of what this date.txt file looks like.


    Not sure about the applescripting part, just tinkered with it tbh, but if it works like most languages you are looking at a line read from text file into a variable type of some kind, doing something like red menace has suggested to that variable and line write out to what you wanted (ideally to a new txt file to keep source intact, just a preference here though).

    Show this date.txt file and they may be able to help you better. I for example am wondering if is just one line of text, the date, or several lines of dates. In any language how you would add the day abbreviation would be based on this.

    Not doubting you per se...but if true I am wondering what app you are using that bothers to create a file with just one date...and no other information to show its meaning. And then on Sun the 17th....either creates a new file or overwrite the old one, again with just single date, no information.
     

Share This Page