Parsing the date out of the filename.

Discussion in 'Mac Programming' started by mobilemario, Feb 7, 2016.

  1. mobilemario macrumors member

    Joined:
    Mar 26, 2009
    #1
    I’m researching if it’s possible to achieve the fallowing:
    I have a file named XYZ-DATE_CREATED*DUE*-DATE_DUE-1234.
    It’s a credit card statement in pdf format.
    XYZ- Name of the bank
    DATE_CREATED- Original date of the statement
    DATE_DUE- The date when payment is due.


    Is there a way to use applescript to automatically create a reminder
    with the due date grabbed from the file's name and the last 4digits and bank as the title?
    I have zero knowledge about scripting so only trying to find a solution.
     
  2. MacUser2525 macrumors 68000

    MacUser2525

    Joined:
    Mar 17, 2007
    Location:
    Canada
    #2
    grep and its ^ and $ for start and end of expression to find could be used with a cron job to do what you want but I am failing to see why you do not use Reminders it has what you need already builtin to OSX.
     
  3. mobilemario thread starter macrumors member

    Joined:
    Mar 26, 2009
    #3
    I have a total of 12 statements, with various dates. Would like automate things a bit ;)
     
  4. superscape macrumors 6502a

    superscape

    Joined:
    Feb 12, 2008
    Location:
    East Riding of Yorkshire, UK
    #4
    Sure there is.

    If you're looking for a pure AppleScript solution then do some reading up on Applescript's text item delimiters. Here's a little to get you started:

    Code:
    set theFileName to "XYZ-DATE_CREATED*DUE*-DATE_DUE-1234.pdf" --just using the example file name
    
    --split the file name up into bits, separated by "-", and get the second 'bit'
    set AppleScript's text item delimiters to "-"
    set theTextItems to every text item of theFileName
    set AppleScript's text item delimiters to ""
    set theTempItem to item 2 of theTextItems
    
    
    --take that second bit, and split it again, this time splitting it by "*" and getting the first bit
    set AppleScript's text item delimiters to "*"
    set theTextItems to every text item of theTempItem
    set AppleScript's text item delimiters to ""
    
    set theDateCreated to item 1 of theTextItems
    
    display dialog "Date Created: " & theDateCreated
    
     

Share This Page