0

I'm trying to use LestMove to be more precise the second implementation method where it says:

Option 2:

Copy the following files into your project:

PFMoveApplication.h PFMoveApplication.m If your project has ARC enabled, you'll want to disable ARC on the above files. You can do so by adding -fno-objc-arc compiler flag to your PFMoveApplication.m source file. See How can I disable ARC for a single file in a project?

If your application is localized, also copy the 'MoveApplication.string' files into your project.

Link your application against Security.framework.

In your app delegate's "-[applicationWillFinishLaunching:]" method, call the PFMoveToApplicationsFolderIfNecessary function at the very top.

but I'm not able to call the method / Class, could someone help me with this issue? Thanks in advance!

2
  • Just as AppleScript handlers need to be in a script object, I think Objective-C methods need to be in a class in order for everything to get linked up. That thing is a bit of a mess for use with ASObjC, are you asking how to use an Objective-C class in general, or how to fix this one in particular? Commented Apr 13, 2020 at 0:24
  • hi red_menace, How to fix this in particular, but it would be nice if you could explain how to do that in general too. Commented Apr 13, 2020 at 15:34

1 Answer 1

1

In general, there are a couple of ways to set up an Objective-C class in your AppleScriptObjC project:

  • Add the file(s) to the project - the Objective-C class name will be the one used in the @interface/@implementation declarations
  • Add an outlet property in the AppleScript class/script you are using, e.g. property someProperty : missing value

    1. Instantiate the class programmatically:

      set someProperty to current application's ClassName's alloc's init()

    or

    1. Connect stuff up with the Interface Builder:
      • Add an NSObject (blue cube) from the library to your project
      • Set the class of the object/cube to the class name of the Objective-C file(s) in the Identity Inspector
      • Connect the AppDelegate IB Outlet to the object/cube in the Connections Inspector
  • After setting up the outlet property, the Objective-C methods can be used like any other script/class:

    someProperty's handler()


That LetsMove project wasn't really set up for AppleScriptObjC, but I was able to tweak it a bit to get it running. I'm not that great at writing Objective-C, but the following worked for me using a new default AppleScript project with Xcode 10 in Mojave (the original file is over 500 lines long, so I'm just highlighting the changes):

  1. Add PFMoveApplication.h and PFMoveApplication.m files to the project (the class name is LetsMove)
  2. Add Security.framework to Link Binary With Libraries in Build Phases
  3. As described in the original project README, add the compiler flag -fno-objc-arc to the Objective-C file in Compile Sources of the Build Phases

-- Now to alter the Objective-C files a bit:

  1. Move the @interface declaration to the .h file and include the redefined method signatures below in it:
  2. The PFMoveToApplicationsFolderIfNecessary and PFMoveIsInProgress methods are redefined as instance methods:

    - (void)PFMoveToApplicationsFolderIfNecessary;
    - (BOOL)PFMoveIsInProgress;
    
  3. Redefine the above method signatures in the .m file, and include those methods in the @implementation section - to do this, move the @end to just before the helper methods (after the PFMoveIsInProgress method)
  4. Remove the isMainThread statement at the beginning of the PFMoveToApplicationsFolderIfNecessary method - this is not not needed (AppleScript normally runs on the main thread), and fixes another issue
  5. There is still a little stuff in there from the original app such as NSUserDefaults, so for your own project, give it a look to see if anything else needs changing (dialog text, etc)

And finally, in the AppDelegate.applescipt file, the following was added to applicationWillFinishLaunching:

    current application's LetsMove's alloc's init()'s PFMoveToApplicationsFolderIfNecessary()
Sign up to request clarification or add additional context in comments.

9 Comments

I tried to implement using only ApplescriptOBJC and it works but I can't relaunch the Application, it just won't open after copying to the Applications folder and closing. code here:pastebin.com/MdK6wyQT
Are you not using that Objective-C class? If you are now doing your own version, note that LetsMove uses an NSTask to perform the quit/relaunch, since once the application quits it obviously won't be running in order to do anything else.
I tried to replace the shell script "mv " & quoted form of POSIX path of myApp & space & "/ Applications" with this: from the shell script "cp -R " & quoted form of POSIX path of myApp & space & "/ Applications" but not working copy only Binary file.
To shut down the app, move it, and start it up from the new location, you will need to launch a separate task, since the app isn't going to continue with anything once it quits - take a look at what the LetsMove Objective-C class is doing (it is in the Relaunch method near the end).
this: NSString *script = [NSString stringWithFormat:@"(while /bin/kill -0 %d >&/dev/null; do /bin/sleep 0.1; done; %@; /usr/bin/open %@) &", pid, preOpenCmd, quotedDestinationPath]; ?
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.