macexec with variable

macexec with variable

Postby plantenkennis » Wed Apr 12, 2017 7:56 pm

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
plantenkennis
 
Posts: 166
Joined: Wed Nov 25, 2015 7:13 pm
Location: the Netherlands

Re: macexec with variable

Postby Antonio Linares » Thu Apr 13, 2017 7:46 am

It seems as we have to use this method:

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

I am going to implement it
regards, saludos

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

Re: macexec with variable

Postby Antonio Linares » Thu Apr 13, 2017 7:50 am

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

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

Re: macexec with variable

Postby Antonio Linares » Thu Apr 13, 2017 8:19 am

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

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

Re: macexec with variable

Postby Antonio Linares » Thu Apr 13, 2017 9:13 am

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

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

Re: macexec with variable

Postby mastintin » Thu Apr 13, 2017 2:33 pm

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
mastintin
 
Posts: 1516
Joined: Thu May 27, 2010 2:06 pm

Re: macexec with variable

Postby plantenkennis » Thu Apr 13, 2017 6:28 pm

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


Kind regards,

René Koot
User avatar
plantenkennis
 
Posts: 166
Joined: Wed Nov 25, 2015 7:13 pm
Location: the Netherlands

Re: macexec with variable

Postby Antonio Linares » Thu Apr 13, 2017 11:35 pm

> 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
Antonio Linares
Site Admin
 
Posts: 42099
Joined: Thu Oct 06, 2005 5:47 pm
Location: Spain

Re: macexec with variable

Postby plantenkennis » Fri Apr 14, 2017 11:46 am

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
plantenkennis
 
Posts: 166
Joined: Wed Nov 25, 2015 7:13 pm
Location: the Netherlands

Re: macexec with variable

Postby Antonio Linares » Fri Apr 14, 2017 7:31 pm

very good
regards, saludos

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


Return to FiveMac / FivePhone (iPhone, iPad)

Who is online

Users browsing this forum: No registered users and 8 guests