My App is to copy a text and numbers to other Applications selected by user such as: Microsoft Word, Text Edit, Excel and some similar apps. I use AppleScriptMBS to call selected app and then activate it and then Paste my text into.
Problem is: if I Write the app name my self it works very good. But if i call it by its name from preferences window were the user choose his favorite app it dose not work. Here is the example:
[code]dim a as new AppleScriptMBS
dim lines(-1) as string
//lines.Append “tell application ““Microsoft Word””” <<<<<<<< This line of code works just fine, I don’t want it
lines.Append "tell application " + Str(Preferences.AppName.text) <<<<<<<< This line of code doesn’t work!! i want to use this
lines.Append " activate"
lines.Append “end tell”
a.Compile Join(lines, EndOfLine.Macintosh)
The : (Preferences.AppName.text) is the saved name of user Application choice, For example: “Microsoft Word” in my application Preferences window.
I don’t want to call App by it’s name because Applications are different from user to user.
Any help Please.
AppleScriptMBS is the old class. NSAppleScriptMBS is the newer one. It’s a bit more work, though.
Your second tell line is missing the quotes
Address the applications by bundle ID and not by name. This works better for Mojave anyways. With the MBS classes you can get the bundle ID out of an application name.
I have a wrapper for NSAppleScriptMBS at https://www.mothsoftware.com/downloads/runAS.zip which I still need to update for Mojave.
Thank you Beatrix,
If I add quotes to this part of code “” + Str(Preferences.AppName.text) + “”", it turns to color pink and Xojo consider it as the Application name not a String and when run asks me where the Application “” + Str(Preferences.AppName.text) + “”"?.
Before i was using PressKeyMBS, it was working fine.
After activate other application
p.keycode = 9
But now with Mac OS Mojave, it doesn’t work any more.
You will run into the same problems with your AppleScript. Have a look at DeterminePermissionToAutomateTarget from the MBS plugin.
Regarding your error: did you add 2 double quotes? Pink sounds like you added single quotes.
lines.Append "tell application """ + Str(Preferences.AppName.text) + """"
Thank You Sam. It works. Very appreciate. Thank you also Beatrix for your help.