Opening a file in AppleScript

Discussion in 'Mac Programming' started by Chemical666, May 5, 2014.

  1. Chemical666, May 5, 2014
    Last edited: May 5, 2014

    Chemical666 macrumors newbie

    Joined:
    May 5, 2014
    #1
    Hi, I have an issue opening a file with applescript, The app is loaded but does not allow to open the type of file directly by double-clicking on it, it has to be opened through the menu bar and then "load configuration". Code works fine up to when comes the time to selct the actual file to open in the Finder "open" window that popped up. How do I specify to AppleScirpt how to go get the file I look for?

    Here is the code I have so far for this part :

    Code:
    tell application "System Events"
    	tell application process "JackPilot"
    		click button "Routage" of window 1
    		click menu item "Charger la configuration..." of menu 1 of menu bar item "Fichier" of menu bar 1
    		get file of window 1  -- alias "Macintosh HD:Users:marc-andre:Desktop:test.jks" ""
    	end tell
    end tell
    
    
    Thanks
     
  2. kryten2 macrumors 6502a

    Joined:
    Mar 17, 2012
    Location:
    Belgium
    #2
    You can try this :

    Code:
    set configurationFile to alias ((path to desktop folder as text) & "test.jks")
    tell application "System Events"
    	tell application process "JackPilot"
    		click button "Routage" of window 1
    		click menu item "Charger la configuration..." of menu 1 of menu bar item "Fichier" of menu bar 1
    		--get file of window 1 -- alias "Macintosh HD:Users:marc-andre:Desktop:test.jks" ""
    		keystroke "g" using {command down, shift down}
    		delay 0.5
    		keystroke configurationFile
    		delay 0.5
    		click button "what's on the button" of sheet 1 of window "title of window" -- or window 1 etc
    		-- more statements
    	end tell
    end tell
    
     
  3. Chemical666 thread starter macrumors newbie

    Joined:
    May 5, 2014
    #3
    Credits to kryten2, it worked! Thanks so much! For those who may encounter the issue, here is the final working code that I used :
    Code:
    tell application "System Events"
    	set frontmost of process "JackPilot" to true
    	tell application process "JackPilot"
    		click button "Routage" of window 1
    		click menu item "Charger la configuration..." of menu 1 of menu bar item "Fichier" of menu bar 1
    		delay 1
    		keystroke "g" using {command down, shift down}
    		delay 0.5
    		keystroke "Bureau"
    		delay 0.5
    		keystroke return
    		delay 1.5
    		keystroke "test.jks"
    		keystroke return
    	end tell
    end tell
    
     

Share This Page