AppleScriptMBS to run other Application

  1. last week

    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:

    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 "Paste"
    lines.Append "end tell"
    
    a.Compile Join(lines, EndOfLine.Macintosh)
    a.Execute

    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.

    Should be

    lines.Append "tell application """ + Str(Preferences.AppName.text) + """" 
  2. Beatrix W

    Dec 2 Pre-Release Testers Europe (Germany)

    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

    lines.Append "tell application """ + Str(Preferences.AppName.text) + """

    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.

  3. 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

     k=new KeyCodesMBS
      p=new PresskeyMBS
      p.command=true
      p.charcode=asc("v")
      p.keycode = 9
      p.Press

    But now with Mac OS Mojave, it doesn't work any more.

  4. Beatrix W

    Dec 2 Pre-Release Testers Europe (Germany)

    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.

  5. Sam R

    Dec 2 Pre-Release Testers, Xojo Pro Answer Hengchun, Pingtung, Taiwan

    Should be

    lines.Append "tell application """ + Str(Preferences.AppName.text) + """" 
  6. Thank You Sam. It works. Very appreciate. Thank you also Beatrix for your help.

or Sign Up to reply!