Page 1 of 1

macexec with variable

PostPosted: Wed Apr 12, 2017 7:56 pm
by plantenkennis
Hello,
Is it possible to add a 'variable' to the MacExec() command?

What I want is the following:
From my program I want to run a .sh file to make directories and move files.

So I want to use the next command: MacExec( "terminal" MoveFilesLite.sh )

Re: macexec with variable

PostPosted: Thu Apr 13, 2017 7:46 am
by Antonio Linares
It seems as we have to use this method:

https://developer.apple.com/reference/appkit/nsworkspace/1534810-launchapplication

I am going to implement it

Re: macexec with variable

PostPosted: Thu Apr 13, 2017 7:50 am
by Antonio Linares
Here we have two ways to do it:

http://stackoverflow.com/questions/5048677/launching-an-mac-app-with-objective-c-cocoa

lets see which one is the right one to use

Re: macexec with variable

PostPosted: Thu Apr 13, 2017 8:19 am
by Antonio Linares
This should work fine:

Code: Select all  Expand view
HB_FUNC( MACEXEC )
{
   NSWorkspace * workspace;

   if( hb_pcount() > 1 )
   {
      workspace = [ [ [ NSWorkspace alloc ] init ] autorelease ];
       
      if( hb_pcount() == 1 )
         hb_retl( [ workspace launchapplication: hb_NSSTRING( 1 ) ] );

      if( hb_pcount() == 2 )
      {
         NSURL * url = [ NSURL fileURLWithPath: [ workspace fullPathForApplication: hb_NSSTRING( 1 ) ] ];
         NSArray * arguments = [ NSArray arrayWithObjects: hb_NSSTRING( 2 ), nil ];
         NSError * error = nil;
         
         hb_retl( [ workspace launchApplicationAtURL:url options:0
           configuration:[NSDictionary dictionaryWithObject:arguments forKey:NSWorkspaceLaunchConfigurationArguments]  
           error:error ] );
      }
   }
}


I am going to try it

Re: macexec with variable

PostPosted: Thu Apr 13, 2017 9:13 am
by Antonio Linares
This code compiles fine:

Code: Select all  Expand view
HB_FUNC( MACEXEC )
{
   NSWorkspace * workspace;

   if( hb_pcount() > 1 )
   {
      workspace = [ [ [ NSWorkspace alloc ] init ] autorelease ];
       
      if( hb_pcount() == 1 )
         hb_retl( [ workspace launchapplication: hb_NSSTRING_par( 1 ) ] );

      if( hb_pcount() == 2 )
      {
         NSURL * url = [ NSURL fileURLWithPath: [ workspace fullPathForApplication: hb_NSSTRING_par( 1 ) ] ];
         NSArray * arguments = [ NSArray arrayWithObjects: hb_NSSTRING_par( 2 ), nil ];
         NSError * error = nil;
         
         hb_retl( [ workspace launchApplicationAtURL:url options:0
           configuration:[NSDictionary dictionaryWithObject:arguments forKey:NSWorkspaceLaunchConfigurationArguments]  
           error:error ] );
      }
   }
}

Re: macexec with variable

PostPosted: Thu Apr 13, 2017 2:33 pm
by mastintin
More simple .... use TASKEXEC ().

This not run property for problems with script paths but build.sh is launch .

@ 150, 40 BUTTON "Terminal" ACTION msginfo( TaskExec( "/bin/sh", Path()+"/build.sh","testget.prg" ) )

Re: macexec with variable

PostPosted: Thu Apr 13, 2017 6:28 pm
by plantenkennis
Hello Mastintin,

Thanks for your suggestion, but this does not work.

What I want is the following:
I use packages to make a pkg from my app. This pkg installs the program in folder programs and databases in folder users/shared/plantenkennis.
Now I want to run a .sh script which makes folder plantenkennis in users/$user and move the files from shared to $user.
I have a script (MoveFilesLite.sh) with all the commands in it. It runs perfect in command tool, but when I implement it in the packages app, the pkg gives an error. The reason is that packages expect a 0 as return after the .sh script.
I don't know how to do this, so i thought is I run the MoveFileLite.sh from my app the first time it is launched it would solve the problem.
But if I run TaskExec( "/bin/sh", "MoveFilesLite.sh", ), nothing happens?

My MoveFilesLite.sh script:
Code: Select all  Expand view

# date: 14-03-2017
# to place all needed databases and other files in the right folder
# first make the folders needed

mkdir /Users/$USER/plantenkennis
mkdir /Users/$USER/plantenkennis/databases
mkdir /Users/$USER/plantenkennis/databases/etiketten
mkdir /Users/$USER/plantenkennis/databases/lijsten
mkdir /Users/$USER/plantenkennis/foto
mkdir /Users/$USER/plantenkennis/fotocomb
mkdir /Users/$USER/plantenkennis/iconen
mkdir /Users/$USER/plantenkennis/temp

# now move the files from users/shared/plantenkennisLite naar /users/$user/Plantenkennis

mv /Users/shared/PlantenkennisLite/databases/*.dbf /Users/$USER/plantenkennis/databases
mv /Users/shared/PlantenkennisLite/databases/*.dbt /Users/$USER/plantenkennis/databases
mv /Users/shared/PlantenkennisLite/etiketten/*.* /Users/$USER/plantenkennis/databases/etiketten
mv /Users/shared/PlantenkennisLite/lijsten/*.* /Users/$USER/plantenkennis/databases/lijsten
mv /Users/shared/PlantenkennisLite/foto/*.jpg /Users/$USER/plantenkennis/foto
mv /Users/shared/PlantenkennisLite/iconen/*.* /Users/$USER/plantenkennis/iconen

# I wanted to delete the empty folders, but that does not work?

# rmdir /Users/shared/plantenkennisLite/databases
# rmdir /Users/shared/plantenkennisLite/etiketten
# rmdir /Users/shared/plantenkennisLite/lijsten
# rmdir /Users/shared/plantenkennisLite/foto
# rmdir /Users/shared/plantenkennisLite/fotocomb
# rmdir /Users/shared/plantenkennisLite/iconen
# rmdir /Users/shared/plantenkennisLite



Re: macexec with variable

PostPosted: Thu Apr 13, 2017 11:35 pm
by Antonio Linares
> But if I run TaskExec( "/bin/sh", "MoveFilesLite.sh", ), nothing happens?

the path of MoveFilesLite.sh is missing

Re: macexec with variable

PostPosted: Fri Apr 14, 2017 11:46 am
by plantenkennis
Hello Antonio,

Yes, you're right. Forgot the path, with the path it works!
Thanks again both for the help.

Re: macexec with variable

PostPosted: Fri Apr 14, 2017 7:31 pm
by Antonio Linares
very good