macexec with variable

Post Reply
User avatar
plantenkennis
Posts: 151
Joined: Wed Nov 25, 2015 7:13 pm
Location: the Netherlands
Contact:

macexec with variable

Post 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 )
Kind regards,

René Koot
User avatar
Antonio Linares
Site Admin
Posts: 37481
Joined: Thu Oct 06, 2005 5:47 pm
Location: Spain
Contact:

Re: macexec with variable

Post by Antonio Linares »

It seems as we have to use this method:

https://developer.apple.com/reference/a ... pplication

I am going to implement it
regards, saludos

Antonio Linares
www.fivetechsoft.com
User avatar
Antonio Linares
Site Admin
Posts: 37481
Joined: Thu Oct 06, 2005 5:47 pm
Location: Spain
Contact:

Re: macexec with variable

Post by Antonio Linares »

Here we have two ways to do it:

http://stackoverflow.com/questions/5048 ... ve-c-cocoa

lets see which one is the right one to use
regards, saludos

Antonio Linares
www.fivetechsoft.com
User avatar
Antonio Linares
Site Admin
Posts: 37481
Joined: Thu Oct 06, 2005 5:47 pm
Location: Spain
Contact:

Re: macexec with variable

Post by Antonio Linares »

This should work fine:

Code: Select all

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
regards, saludos

Antonio Linares
www.fivetechsoft.com
User avatar
Antonio Linares
Site Admin
Posts: 37481
Joined: Thu Oct 06, 2005 5:47 pm
Location: Spain
Contact:

Re: macexec with variable

Post by Antonio Linares »

This code compiles fine:

Code: Select all

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 ] );
      }
   } 
}
regards, saludos

Antonio Linares
www.fivetechsoft.com
User avatar
mastintin
Posts: 1502
Joined: Thu May 27, 2010 2:06 pm

Re: macexec with variable

Post 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" ) )
User avatar
plantenkennis
Posts: 151
Joined: Wed Nov 25, 2015 7:13 pm
Location: the Netherlands
Contact:

Re: macexec with variable

Post 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

# 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


Kind regards,

René Koot
User avatar
Antonio Linares
Site Admin
Posts: 37481
Joined: Thu Oct 06, 2005 5:47 pm
Location: Spain
Contact:

Re: macexec with variable

Post by Antonio Linares »

> But if I run TaskExec( "/bin/sh", "MoveFilesLite.sh", ), nothing happens?

the path of MoveFilesLite.sh is missing
regards, saludos

Antonio Linares
www.fivetechsoft.com
User avatar
plantenkennis
Posts: 151
Joined: Wed Nov 25, 2015 7:13 pm
Location: the Netherlands
Contact:

Re: macexec with variable

Post by plantenkennis »

Hello Antonio,

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

René Koot
User avatar
Antonio Linares
Site Admin
Posts: 37481
Joined: Thu Oct 06, 2005 5:47 pm
Location: Spain
Contact:

Re: macexec with variable

Post by Antonio Linares »

very good
regards, saludos

Antonio Linares
www.fivetechsoft.com
Post Reply