2

I have an AppleScript file which works like a charm, except for the part where I use keystrokes to make VLC run fullscreen. The filename has been changed for privacy reasons, but the rest of the code is the exact same. My code goes as this:

tell application "Finder"
    set MyFile to ((path to me as text) & "File.mkv") as text
end tell
tell application "VLC"
    open MyFile
end tell
tell application "System Events"
    tell application process "VLC"
        set frontmost to true
        keystroke "f" using command down
    end tell
end tell
  • 3
    How is the AppleScript code being executed? Is it saved as an .app and the target MyFile placed within the root of the application bundle? I'm asking because, I don't see how your first tell block could return a properly formed pathname to the target file otherwise. – user3439894 May 21 '17 at 17:10
2

You don't need to tell VLC to perform the keystroke.

tell application "VLC"
    open MyFile
    activate
end tell
tell application "System Events"
    keystroke "f" using command down
end tell

I understand you say the rest of the script works, but without more information, I don't see how.

path to me will return the path to the actual script, not the containing folder. This means you'll end up with the equivalent of path:to:script.scptFile.mkv, which can't be true. Instead, you need to get the container:

tell application "Finder"
    set MyFile to ((container of (path to me) as text) & "File.mkv") as text
end tell

This will return path:to:File.mkv. Make sure your mkv is actually in this location.


Full script:

tell application "Finder"
    set MyFile to ((container of (path to me) as text) & "File.mkv") as text
end tell
tell application "VLC"
    open MyFile
    activate
end tell
tell application "System Events"
    keystroke "f" using command down
end tell
  • sorry, not all the code got copied... it actually was "set MyFile to ((path to me as text) & "Contents:Resources:File.mkv") as text... I'm going to test your script and see how it goes. edit Nice, it worked... thanks! – FranckTheMiner May 21 '17 at 19:31

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .