Hello,
I am trying to launch a file, SpecialFolder.Desktop.child(“links.txt”), programatically with TextEdit, it does not launch but the message box is displayed.
What could be the problem?
Dim document As FolderItem
Dim TextEditApp As FolderItem = SpecialFolder.Applications.child("TextEdit.app")
document = SpecialFolder.Desktop.child("links.txt")
// https://forum.xojo.com/t/launch-and-open-file/54435/2
dim sh as new shell
dim command as String = "open -a " + TextEditApp.ShellPath + " " + document.ShellPath
sh.Execute(command) // Does not work
msgbox "Button pressed"
Hi Lennox,
First check the return code after the shell execution and test by running the command from the terminal.
It should give you some information.
dim command as String = "open -a /System" + TextEditApp.ShellPath + " " + document.ShellPath
This work too (if you prefer to change the SpecialFolder code, so change below without changing the above code):
'Dim TextEditApp As FolderItem = SpecialFolder.Applications.child("TextEdit.app")
Dim TextEditApp As FolderItem = SpecialFolder.System.child("Applications").child("TextEdit.app")
The application /Applications/TextEdit.app cannot be opened for an unexpected reason, error=Error Domain=NSCocoaErrorDomain Code=260 “The file “TextEdit.app” couldn’t be opened because there is no such file.” UserInfo={NSURL=file:///Applications/TextEdit.app, NSFilePath=/Applications/TextEdit.app, NSUnderlyingError=0x600002a51440 {Error Domain=NSPOSIXErrorDomain Code=2 “No such file or directory”}}
right click on TextEdit.app and Get Info
where information to find where really TextEdit.app is (/System/Applications)
If you want to always find the correct folder (or FolderItem) of an application (no matter which macOS version, if it’s in /Applications or /System/Applications, or maybe even /Users/username/Applications), then have a look at this example project showing the “macOS way(s)” of finding that (best: search by it’s BundleID):