Hey @dealtek,
Setting a string to a string is a trifle redundant β path-string or not.
set myStr to "I'm just a string..."
return class of myStr
It should also be noted that string has been deprecated in favor of text (unicode text) for a very long time now.
See the Text_Class_link in the Applescript Language Guide.
@ComplexPoint is using an alias file-reference in his example, and I actually prefer this method. Aliases go back to Apple's HFS file system and rely on HFS paths which are delimited with a colon β:β rather than a forward slash β/β like POSIX Paths.
Unfortunately Apple decided to reduce the functionality of aliases in either High Sierra or Mojave, and I reckon this has to do with changes related to the APFS (Apple File System). Aliases in AppleScript no longer keep track of items even when their name/location has changed. (Major bummer.)
Since macOS is increasingly Unix-centric, this example is going to focus on using POSIX Paths.
(I'll post something more universal later.)
NOTE β dragging a file into Apple's Script Editor app will create a POSIX Path, but if you're not paying attention it might try to open the file as text. That can be especially problematic if the file in question is a large movie or application.
After spending a few minutes testing with it today I can't believe anyone would want to write AppleScript if they had to fight with this awful app constantly. Thank goodness Script Debugger Lite is available for free and is so completely superior. (I've used the professional commercial version since 1996.)
Drag and drop in Script Debugger gives you many more options that the Script Editor:
--------------------------------------------------------
# Auth: Christopher Stone
# dCre: 2021/02/06 09:50
# dMod: 2021/02/06 14:37
# Appl: QuickTime Player, System Events
# Task: Open a given file in the QuickTime Player.
# Libs: None
# Osax: None
# Tags: @Applescript, @Script, @QuickTime_Player, @System_Events
--------------------------------------------------------
# Fully hard-coded POSIX Path -- NOT recommended.
--------------------------------------------------------
# set posixFilePath to "/Users/YourUserName/Desktop/TEST VID.mp4"
--------------------------------------------------------
# Better:
# $HOME folder based or Tilde format POSIX Path β~/β --> (root user folder).
--------------------------------------------------------
set posixFilePath to "~/Desktop/TEST VID.mp4"
--------------------------------------------------------
# I personally prefer the following method of creating what I call an "Anchored Alias".
# This is the method @ComplexPoint illustrated.
# Fortunately I have a hotkey-driven script to create these automagically which makes using them effortless instead of tedious.
# Anchored paths are _nearly always_ better than hard-coded paths.
# set fileRefAlias to alias ((path to downloads folder as text) & "TEST VID.mp4")
--------------------------------------------------------
set posixFileRef to make_Posix_FileRef_From_POSIX_Path(posixFilePath)
--------------------------------------------------------
# For TESTING.
--------------------------------------------------------
# set hfsPathStr to (posixFileRef as text)
# set posixPathStr to POSIX path of (posixFileRef as text)
--------------------------------------------------------
tell application "QuickTime Player"
# Starts up the app without the open file dialog.
# Not necessary in this use-case, but often a good idea.
if not running then launch
-----------------------------------------------------
# For TESTING.
-----------------------------------------------------
# open hfsPathStr -- Works on Sierra, but Mojave doesn't like it.
# open posixPathStr -- Works on Sierra, but Mojave doesn't like it.
-----------------------------------------------------
# Activate "appName" brings an application to the front, launching it if necessary.
# A proper file-reference is needed on Mojave.
# - Sierra was tolerant of a path string β either HFS or POSIX.
-----------------------------------------------------
activate
# Open the previously defined file-ref and assign the document-object to a variable.
set newDoc to open posixFileRef
# Play the newly opened document.
play newDoc
end tell
--------------------------------------------------------
--Β» HANDLERS
--------------------------------------------------------
on make_Posix_FileRef_From_POSIX_Path(posixFilePath)
tell application "System Events"
set fileRef to POSIX path of disk item posixFilePath
end tell
set posixFileRef to POSIX file fileRef
return posixFileRef
end make_Posix_FileRef_From_POSIX_Path
--------------------------------------------------------
When you write code you're lucky when things are simple...
Once you gain some proficiency with a given scripting/programming language many things become relative shades of easy, but few things are truly simple. Too many finicky details toss simple out with the bathwater.
-Chris