I am attempting to create an automator app that executes a bash script which in turn uses some resource files (e.g. it deploys a docker-compose.yml file that I created).
I intend to share this app with my colleagues but I am having problems accessing the resource files. Regardless where the app is located if its script does this:
MYPATH=$(pwd) && osascript -e 'display alert "'"$MYPATH"'"'
home ~ gets displayed everytime. This is a problem because I have no way of knowing in which directory my colleagues are going to place the app and its script needs to know where the resource files are located.
Does anyone suggest a good approach to solve this? E.g. a bash command that returns the app location would be nice. I am not interested in any approach that requires instructing someone to place the app in a specific directory.
I solved it using path to me of the Run AppleScript option:
Its return value is passed as argument $1 to the next step.
Related
I have a shell script, and a tarball. The shell script unpacks the tarball, and makes use of the files inside of for performing a task. I need to make this accessible on mac laptops, but in such a way that there is either a .app or .dmg file that when clicked, ultimately calls that shell script. I found several utilities, that can do this (create such an .app file), such as Platypus, or Appify. However, these require Mac to build the file. The thing is, I must package the .app/.dmg file, in an Ubuntu environment.
Is there any good software for creating a dmg or app file which call a shell script when clicked, but such that the software which can be run in Ubuntu (just for the purpose of creating the file)?
This is not an exact answer to your question but an workaround that might be acceptable if you can't find a better solution.
First, a zip file will automatically extract its content if you double click it in OS X so
tar -cvzf your_filename.zip ...
would create a file that can be easily extracted.
Secondly, if you create a shell script that has the extension .command, but otherwise is like any shell script, it can be run from OS X by double clicking on it (by opening a terminal and executing it there), it would mean an extra manual step for the user but like I said, this is a workaround :)
If you create a .command file, remember to make it executable.
I've built a script that places an icon in the launcher to open a program as the root user. This script also adds NOPASSWD to the user's configuration for this specific app in /etc/sudoers, however the one part of the script that refuses to work is the creation of the profile in /root/.config/<app>. I can create this manually, using the same mkdir command, but when I place the same command in the script it returns no such file or directory. I have replicated this behaviour a number of times, including on a clean install.
Is there some form of protection that disallows the ability to automate the creation of this directory? Or am I missing something about hidden folders in Linux?
I assume you are doing this when the .config dir does not exist yet.
mkdir /root/.config/<app>
Try this :
mkdir -p /root/.config/<app>
This will create any missing parent directory to the full path you provide.
I'm using Bash on Windows and what I'm missing is a good IDE. I've tried running a GUI app with the following tutorial but it doesn't work well every time and it's frustrating.
What I want is to run the script that would copy the files from a folder on Windows into a folder on Unix subsystem, but only the files that are different. And same for the other direction (if I change something from terminal, to be updated in the Windows folder). I want that script to be run every time I call ./SOME_EXECUTABLE in that folder. For the check weather the file was changed or not I can use hg status because I'm mostly working with Mercurial.
Is there a way to do this without making a separate shell script that would combine those calls? Something like a macro.
You could use a function in .bashrc to achieve your requirement, and run your required script that copies stuff from across machines as you needed. Assuming you have the script in place, lets say, e.g. copyScript.sh you can add a function like
function copyOnExecute() {
./copyScript.sh
./EXECUTABLE
}
This way you can call the function copyOnExecute, every time you want to run your executable.
You could add an alias to .bash_aliases such as:
alias execute="./copyScript.sh && ./$1"
You can replace ./ with your scripts path
This runs the executable after your script has finished, and only if it finished successfuly.
It would be easier for you then writing a function in one of the .rc files
If you'd write a function called execute, in the future you might forget where It was written, using an alias helps you avoid this.
I am trying to run a bash file from install4j6. install4j does indeed try to run the bash file but it just returns an error at the end of the installation. The error is very generic and has no code reference or anything that will help me determine a solution - just a message that says "Error while executing file."
The only thing I can provide is how I have it setup in install4j6 since I am pretty sure that's my issue.
The bash file is defined in the root of my installation directory distribution tree and is named set_permissions.sh. For the sake of eliminating permissions being a cause, the file permission mode is set to 777 (both in install4j and on the file system).
I believe the issue is related to what I have set as my "working directory". I currently have it set to just ".". Is there a way to debug this further? Maybe get an actual error as to why it's not executing?
Ok, first a few things to check:
make sure that you're running the batch file after the install files step (you mention it being at the root of your install)
best to have the wait for termination checked and a variable for the return code.
redirect stderr to the log file (just in case)
As for working directory, . should work, but you can change it to ${installer:sys.installationDir} to make sure that it references the installation directory chosen by the user. You can also set the executable in the form of ${installer:sys.installationDir}\set_permissions.sh
Also, try and run just your shell script to make sure that it works :)
The goal of my cocoa command line program is to take an argument which is the name of a file and import it into the program for parsing. I want to be able to call my program lets say, "ParseFile" from the terminal in mac os, with the argument "Filename.txt"(example$ ParseFile filename.txt), but so far I cant understand how my program can know the absolute path to Filename.txt.
For instance when you use 'cp filename.txt /whateverfolder/filename2.txt' you are copying the file 'filename.txt' from the current working directory of the terminal to a folder called whateverfolder on the root directory. How does cp know the absolute path of filename.txt? if i had filename.txt on my desktop cp would know that i sent it /Users/username/Desktop/filename.txt. This is what I want my program to know.
I have been able to get my program to know where it is executed in, but this is very different from where the current working directory of the bash terminal was at the time of being called.
How do i solve this? Thanks a lot
Use NSFileManager's currentDirectoryPath method:
NSString *currentpath = [[NSFileManager defaultManager] currentDirectoryPath];
How does cp know the absolute path of filename.txt?
It does not know it and doesn't have to. It can just use the relative path. The current working directory is inherited from the parent process.
I have been able to get my program to know where it is executed in, but this is very different from where the current working directory of the bash terminal was at the time of being called.
What do you mean? The directory where the executable is in? That's usually not of much interest. The only other directory that plays a role in this context is the current working directory. If you already got that, what else do you need?