macexec with variable
- plantenkennis
- Posts: 151
- Joined: Wed Nov 25, 2015 7:13 pm
- Location: the Netherlands
- Contact:
macexec with variable
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 )
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
René Koot
- Antonio Linares
- Site Admin
- Posts: 37481
- Joined: Thu Oct 06, 2005 5:47 pm
- Location: Spain
- Contact:
Re: macexec with variable
It seems as we have to use this method:
https://developer.apple.com/reference/a ... pplication
I am going to implement it
https://developer.apple.com/reference/a ... pplication
I am going to implement it
- Antonio Linares
- Site Admin
- Posts: 37481
- Joined: Thu Oct 06, 2005 5:47 pm
- Location: Spain
- Contact:
Re: macexec with variable
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
http://stackoverflow.com/questions/5048 ... ve-c-cocoa
lets see which one is the right one to use
- Antonio Linares
- Site Admin
- Posts: 37481
- Joined: Thu Oct 06, 2005 5:47 pm
- Location: Spain
- Contact:
Re: macexec with variable
This should work fine:
I am going to try it
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 ] );
}
}
}
- Antonio Linares
- Site Admin
- Posts: 37481
- Joined: Thu Oct 06, 2005 5:47 pm
- Location: Spain
- Contact:
Re: macexec with variable
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 ] );
}
}
}
Re: macexec with variable
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" ) )
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" ) )
- plantenkennis
- Posts: 151
- Joined: Wed Nov 25, 2015 7:13 pm
- Location: the Netherlands
- Contact:
Re: macexec with variable
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:
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
René Koot
- Antonio Linares
- Site Admin
- Posts: 37481
- Joined: Thu Oct 06, 2005 5:47 pm
- Location: Spain
- Contact:
Re: macexec with variable
> But if I run TaskExec( "/bin/sh", "MoveFilesLite.sh", ), nothing happens?
the path of MoveFilesLite.sh is missing
the path of MoveFilesLite.sh is missing
- plantenkennis
- Posts: 151
- Joined: Wed Nov 25, 2015 7:13 pm
- Location: the Netherlands
- Contact:
Re: macexec with variable
Hello Antonio,
Yes, you're right. Forgot the path, with the path it works!
Thanks again both for the help.
Yes, you're right. Forgot the path, with the path it works!
Thanks again both for the help.
Kind regards,
René Koot
René Koot
- Antonio Linares
- Site Admin
- Posts: 37481
- Joined: Thu Oct 06, 2005 5:47 pm
- Location: Spain
- Contact: