Marking file as executable on OSX using C (Carbon, standard C/C++) - macos

I'm looking for a way to programatically set the 'executable' bit on a file on OS X. I don't want to invoke 'chmod a+x' but I want the same effect as the chmod call. Any suggestions? A carbon API or any other C/C++ function would work...

See chmod(2), e.g. http://www.manpagez.com/man/2/chmod/osx-10.4.php (I think it's unchanged in 10.5).

There is a "chmod" C library call. Go to a terminal window and type "man 2 chmod".

Related

Creating shorthands for commands in vscode terminal?

It is possible to create git shorthands by defining alias in .gitconfig.
Is there a similar facility for all command line options. Say I am not interested in typing npm run build && node index.js, is there an option to define this with a short hand like bld-run.
I know this is theoretically possible but can't find clear documentation for this.
Please point me in the right direction.
Thank u for the tip #alex. Posting the answer for future enthusiasts.
In mac os mojave, open ~/.bash_profile in any text editor.
type as follows alias c="clear" and save the file.
Open new terminal and type c and your terminal will be all clear.
Same goes for other commands as well.

Running Octave-cli on Iterm/Zsh/Omgzsh in Mac OSX

It feels impossible to get it to run on any custom terminal. I know that octave-cli.app is there but it always opens in the standard terminal. Any ways to execute octave scripts like a compiler (or) run it interactively like an interpreter from Iterm?
Using Mac OSX 10.9+
Edit:
I know how to export path variables. But having searched the web can't find a way to do it. Is it even possible? I even tried it using homebrew to no avail.
You can see the content of octave-cli.app, it's a script. Mine goes like this
open -a Terminal.app /usr/local/octave/3.8.0/bin/octave | logger 2>&1
It specify the terminal application used to open octave. This is the reason of your problem, as I think.
The solution is linking octave-cli in system path, better locates at "/usr/local/bin". like
ln -s /usr/local/octave/3.8.0/bin/octave-cli /usr/local/bin/octave-cli
Finally, octave can be accessed via any terminal(like iTerm) or shell(bash, zsh) by just type "octave-cli" command, which will be searched in system path and found to executed directly.

Emacs custom shell commands

Is there a possability in Emacs to run custom commands or a set of commands (eg. shell) with a user defined emacs shortcut/hook?
To make this clearer. I am working with an embedded system (target), but developing on the host. After writing and compiling code (eg using emacs compile command), I would like to copy (eg. scp) the binary to the system right away.
Furthermore it would be good if the custom shorcut/hook would be easy to adjust (eg. ip address of the target).
Btw: I am aware of the "shell-command" in emacs, but that is not quite what I am looking for.
Would appreciate any advice. Thanks!
I ended up using C-x C-f /root#my-target-ip:/tmp/myfile to edit the file directly on the target. Then you can run it with shell-command ./myfile from within emacs.

terminal command from Python in OS X

Is there a good way to differentiate between OS implementation errors (I'm thinking about OSX's shipped version of python) vs a general error?
Is this raising an exception because it's clearly an Apple/OSX specific command and outside of normal script commands that subprocess.call expects?
If so, how should I get python to mimic the behavior of my typing that command out in terminal?
subprocess.call("defaults write com.apple.finder AppleShowAllFiles YES")
I use this command to edit plists via python (in this case, the Munki MangedInstalls.plist):
subprocess.call(' /usr/bin/defaults write /Library/Preferences/ManagedInstalls InstallAppleSoftwareUpdates 1 ', shell=True)
And this command to read the same plist:
os.popen(' /usr/bin/defaults read /Library/Preferences/ManagedInstalls InstallAppleSoftwareUpdates ').read()
(I realize this thread is a few months old but figured I would post this incase anyone is looking for this information in the future.)

Is there anything similar to binfmt-support on mac OS X?

What I wish to know is whether there is something similar to binfmt-support on mac.
I have a nacl binary executable and I wish to make mac aware of the executable format so thatI can run this executable from command prompt directly.
I have seen people using binfmt-support on linux to achieve this.
Just to explain what I want in more simple terms - Say I have a.nexe file. I can run this file on mac terminal with command "../tools/sel_ldr_x86_32 -B ../tools/irt_core_x86_32.nexe a.nexe"
Instead of this big command, I wish to simply run it like "./a.nexe" and my shell file should then get invoked which would eventually call the command like "../tools/sel_ldr_x86_32 -B ../tools/irt_core_x86_32.nexe a.nexe"
If the file itself is binary, so you can not add a #! to the start of the file, then so far as I know you only have one option; create an alias for the command line in your ~/.bashrc file:
alias nacl='/path/to/sel_ldr_x86_32 -B /path/to/irt_core_x86_32.nexe'
which would then let you type nacl a.nexe at the command line.
NOTE: You will want to use absolute paths in your alias for this to work correctly.

Resources