"Date modified" script strange behavior in Mavericks

Discussion in 'Mac Programming' started by Remcokw, Mar 11, 2014.

  1. Remcokw macrumors newbie

    Joined:
    Jul 31, 2010
    #1
    Does anyone know why this Date Modified script is not working anymore in Mavericks?

    I know there are some security issues in Mavericks and I have added applescript, finder, terminal and the script itself (Saved as application) in the Accessbility tab in security and privacy.

    When dragging a file onto the script application the date modified changes in 14-12-2036 (!)

    Whats going wrong here???:confused:


    Code:
    on open files_
      display dialog "enter the new creation date in format YYYYMMDDhhmm ex: 200112251730:" default answer "" buttons {"Cancel", "Continue"}
      copy the result as list to {the new_creation_date, the button_pressed}
      repeat with file_ in files_
        tell application "Finder"
          set file_ to POSIX path of file_
          do shell script "touch -t " & new_creation_date & " " & quoted form of file_
        end tell
      end repeat
    end open
     
  2. kryten2 macrumors 6502a

    Joined:
    Mar 17, 2012
    Location:
    Belgium
    #2
    What did you set the new_creation_date to or did you leave it blank? I would also move the do shell script statement outside of the tell "Finder" block.
     
  3. mrichmon macrumors 6502a

    Joined:
    Jun 17, 2003
    #3
    Since the date is provided by the user, one thing to check is what date was typed in by the user.

    As a general coding observation, it seems very strange to collect a flag indicating which button was clicked by the user but never checking the value of the flag. (For example, have you tested the "Cancel" behavior? It looks like the file dates will change no matter which button is clicked.)
     
  4. kryten2 macrumors 6502a

    Joined:
    Mar 17, 2012
    Location:
    Belgium
    #4
    Good observation mrichmon. I completely looked over that fact.
     
  5. Remcokw thread starter macrumors newbie

    Joined:
    Jul 31, 2010
    #5
    Hi there, thanks for the tips.

    This script used to work fine in SL and Lion.

    I have tried the Cancel button. It does work but indeed gives an error. At least it doesn't change the date modified of the file.

    New date is set to any date. I have tested this many many times with different dates. Last attempts where: 201401012345

    Move the script statement outside the finder block.. Can you give an example?

    Thanks!
     
  6. kryten2, Mar 12, 2014
    Last edited: Mar 12, 2014

    kryten2 macrumors 6502a

    Joined:
    Mar 17, 2012
    Location:
    Belgium
    #6
    You can remove the tell "Finder" block completely.

    Code:
    on open files_
    	set {new_creation_date, button_pressed} to {text returned, button returned} of (display dialog "enter the new creation date in format YYYYMMDDhhmm ex: 200112251730:" default answer "" buttons {"Cancel", "Continue"})
    	if button_pressed is "Continue" then
    		repeat with file_ in files_
    			set file_ to POSIX path of file_
    			do shell script "touch -t " & new_creation_date & " " & quoted form of file_
    		end repeat
    	end if
    end open
    
     
  7. Remcokw thread starter macrumors newbie

    Joined:
    Jul 31, 2010
    #7
    Marvelous ! It works again ! :)

    Haven't tried this one before !

    Thanks a lot Kryten2 Dank je wel !! (I am Dutch)

    Great help ! :)
     
  8. kryten2 macrumors 6502a

    Joined:
    Mar 17, 2012
    Location:
    Belgium
    #8
    Kleine moeite. Graag gedaan.
    No trouble. You're welcome.
     

Share This Page