Reputation: 936
I have written a little AppleScript which returns "missing value" and I have no idea why this happens. The script is doing what it should do, but the output is not nice in my application where I use it.
The principle of this script is just to take the argument and run the file (with "VLC Media Player") which is provided through the argument.
So for example a use would be osascript open_video.scpt ~/Path/To/File/File.mp3
on run argv
tell application "VLC"
activate
open argv
end tell
end run
Upvotes: 1
Views: 1167
Reputation: 7565
This question is old but brought to the top of the questions by a new answer before I added this answer.
The recently posted answer suggests this issue might be caused if there isn't an ending newline character, and this is not at all true in this case as I've tested both with and without an ending newline character and get the exact same results, both with compiled and plain text AppleScript scripts.
You do not need to have an ending newline character and it has nothing to do with why your code is returning missing value
.
Looking in the AppleScript Dictionary for the open
command, it shows the following:
open v : Open an object.
open alias : The file(s) to be opened.
→ document
Where the → represents returns as in it returns info about the documents, e.g. its name.
In this case VLC is returning missing value
instead, and probably because VLC does not integrate AppleScript as nice as e.g. Apple's own apps.
If you do not want to see missing value
then add a return ""
to the code and it will return a blank line. Or you could add e.g., return "VLC is now playing: & (argv as string)
; however, because VLC's AppleScript integration is not the best, I'd just go with return ""
as VLC does not respond to standard AppleScript error handling well. Again, an observation by testing error handling code that works with other apps but not VLC.
Or just simply directly use the command line open
command, e.g:
open "/Applications/VLC.app" "/path/to/media_file.ext"
Which will open the VLC app, start the media_file.ext
file, and return the prompt.
Upvotes: 1
Reputation: 1866
Did you make sure that you have a newline on the end of the last line? For me I got this error when I had a script that ended abruptly at the last character of the script, instead of having a newline at the end.
AFAIK this doesn't affect the functionality of your script, just what it returns. In my case I got some other output instead after I made this change, but the output appeared to be merely informational.
Upvotes: 0
Reputation: 3792
In my testing, you have to coerce the passed variable to a string.
osascript open_video.scpt '~/Path/To/File/File.mp3'
with a script as such:
on run argv
tell application "VLC"
activate
open (argv as string)
end tell
end run
Upvotes: 0