AppleScript no longer remembers last used folder in Mavericks 10.9

Discussion in 'Mac Apps and Mac App Store' started by freiheit, Jan 9, 2014.

  1. freiheit macrumors 6502a

    Joined:
    Jul 20, 2004
    Location:
    California
    #1
    Hoping for some Applescript advice. I have this simple script which I used a lot in Snow Leopard 10.6.8. The purpose is to ask the user (me) to select a folder and then to launch a random file from within that folder.

    Code:
    tell application "Finder"
    	activate
    	set theFolder to (choose folder)
    	set theFileList to every file of theFolder
    	set FileToOpen to some item of theFileList
    	open FileToOpen
    end tell
    In 10.6 the script somehow "remembers" which folder was selected between runs and will automatically re-open in the last selected folder the next time.

    In 10.9 the script defaults to the last used base-level folder within my home folder (e.g. ~/Movies or ~/Pictures, etc.) but refuses to remember the specific sub-folder (e.g. ~/Movies/Comedies).

    Any ideas? Thank you.
     
  2. kryten2 macrumors 6502a

    Joined:
    Mar 17, 2012
    Location:
    Belgium
    #2
    I don't see this kind of behaviour here. Move the set theFolder to (choose folder) statement outside of the tell application "Finder" block and it will automatically re-open in the last selected folder the next time. Choose file is part of the StandardAdditions dictionary and should never be inside a tell application "Finder" block.

    Code:
    set theFolder to (choose folder)
    
    tell application "Finder"
    	activate
    	set theFileList to every file of theFolder
    	set FileToOpen to some item of theFileList
    	open FileToOpen
    end tell
    or

    Code:
    set theFolder to (choose folder)
    
    tell application "Finder"
    	open some item of theFolder
    end tell
     
  3. freiheit thread starter macrumors 6502a

    Joined:
    Jul 20, 2004
    Location:
    California
    #3
    Working even less well

    Thank you for the suggestion. The shortening of the whole randomization bit is appreciated. I didn't realize it could be that straightforward.

    However after moving the (choose folder) bit outside of the tell statement, the script is going to my Documents folder every time now, no matter what folder I selected the previous time I ran the script.

    Is there a chance (any known issues doing this) that the issue is related to me choosing a folder which is outside of my user home? Home is on an SSD now and all my media is on a separate drive.

    ----------

    Okay, this just got more interesting. If I run the script directly from Applescript Editor it works as expected. Launching it from the Scripts menu on my Mavericks menu bar shows the strange behavior mentioned in my original post.
     

Share This Page