Ask Different (Apple)
Q&A for power users of Apple hardware and software
Latest Questions
5
votes
6
answers
12144
views
Compare multi-digit version numbers in bash
Trying to write a script that searches for the version of the Application then returns the value. My problem is the value is three to four intergers long (example 4.3.2). I have searched for a while and can't find any syntax that would allow you to use a != or -ge for anything higher than a number w...
Trying to write a script that searches for the version of the Application then returns the value. My problem is the value is three to four intergers long (example 4.3.2).
I have searched for a while and can't find any syntax that would allow you to use a != or -ge for anything higher than a number with periods in it. Just wondering if anyone has a better way or I will just keep adding for every version release.
### What I want
else if [ $version1 -ge "9.0.8" ]; then
### How it is written now
vercheck=
mdls -name kMDItemVersion /Applications/iMovie.app
version=echo ${vercheck:17}
version1=echo ${version:1:5}
[...]
else if [ $version1 = "9.0.8" ]; [ $version1 = "9.1.1" ]; then
echo "You already have this version or a higher version installed"
exit 0
balooga1
(51 rep)
Mar 1, 2013, 04:52 PM
• Last activity: Aug 6, 2025, 04:04 AM
2
votes
3
answers
2338
views
How to fix locate.updatedb not respecting directory excluded from /etc/locate.rc?
I wanted to exclude some directories from the results of `/usr/libexec/locate.updatedb` by editing `/etc/locate.rc`. Unfortunately if I edit `locate.rc` `locate.updatedb` runs forever and does not actually terminate -- I have to kill it, and then the database for locate is an empty file. Any ideas o...
I wanted to exclude some directories from the results of
/usr/libexec/locate.updatedb
by editing /etc/locate.rc
. Unfortunately if I edit locate.rc
locate.updatedb
runs forever and does not actually terminate -- I have to kill it, and then the database for locate is an empty file.
Any ideas on why locate.rc
is not respected?
I'm on ML (OS X 10.8), using bash from Macports (bash 4.2.37(2)-release), and my locate.rc
reads:
#
# /etc/locate.rc - command script for updatedb(8)
#
# $FreeBSD: src/usr.bin/locate/locate/locate.rc,v 1.9 2005/08/22 08:22:48 cperciva Exp $
#
# All commented values are the defaults
#
# temp directory
#TMPDIR="/tmp"
# the actual database
#FCODES="/var/db/locate.database"
# directories to be put in the database
#SEARCHPATHS="/"
# directories unwanted in output
PRUNEPATHS="/tmp /var/tmp /Users/me/.vim /Users/me/.cups /Users/me/tmp"
# filesystems allowed. Beware: a non-listed filesystem will be pruned
# and if the SEARCHPATHS starts in such a filesystem locate will build
# an empty database.
#
# be careful if you add 'nfs'
#FILESYSTEMS="hfs ufs"
user1256923
(3642 rep)
Aug 10, 2012, 03:28 PM
• Last activity: Jul 28, 2025, 02:35 PM
39
votes
3
answers
73239
views
Using bash/terminal to get number of battery recharge cycles
I would like to get the number of recharge cycles using bash (terminal commands). I understand the following command will display all of the battery data, but I want the cycle count on its own ioreg -l -w0 |grep Capacity I use the following command to get the battery percentage, so I imagine it can...
I would like to get the number of recharge cycles using bash (terminal commands). I understand the following command will display all of the battery data, but I want the cycle count on its own
ioreg -l -w0 |grep Capacity
I use the following command to get the battery percentage, so I imagine it can be modified slightly to get the cycle count instead;
ioreg -l | awk '$3~/Capacity/{c[$3]=$5}END{OFMT="%.3f";max=c["\"MaxCapacity\""];print(max>0?100*c["\"CurrentCapacity\""]/max:"?")}'
I'm new to bash, so I'm not completely sure how that code works, or how I'd adapt it for my needs.
Any help would be appreciated. Thanks.
Joseph
(1251 rep)
Jan 8, 2014, 03:31 PM
• Last activity: Jul 25, 2025, 11:23 AM
1
votes
1
answers
47
views
Adding a reminder with keith/reminders-cli, upon passing its attributes with json?
I discovered https://github.com/keith/reminders-cli and found it supports also json. How can I use it with jq to add a new entry with desired attribute? I tried the following ``` json_string=$(jq -n --arg duedate "$myduedate" --arg title "$mytitle" '{ "dueDate": $duedate, "title": $title }') reminde...
I discovered https://github.com/keith/reminders-cli and found it supports also json.
How can I use it with jq to add a new entry with desired attribute? I tried the following
json_string=$(jq -n --arg duedate "$myduedate" --arg title "$mytitle" '{ "dueDate": $duedate, "title": $title }')
reminders add "$list" -f json $json_string
but does not work: it puts the json string as "title".
I prefer reminders-cli to Apple Script or Javascript, and I would love to use json and jq to make my script more tidy, compared to others reminders-cli flag and argument.
Michele
(11 rep)
Jan 10, 2025, 05:04 PM
• Last activity: Jul 16, 2025, 09:05 AM
0
votes
1
answers
132
views
How to write a bash script to delete El Capitan Installer
I've been given the below plist which points to a bash script. The script is supposed to delete the installer (El capitan.app) after it has been downloaded to prevent people from upgrading to it. It is not working and I am not sure what needs changing/tweaking, if anything, to the script. It fails t...
I've been given the below plist which points to a bash script.
The script is supposed to delete the installer (El capitan.app) after it has been downloaded to prevent people from upgrading to it.
It is not working and I am not sure what needs changing/tweaking, if anything, to the script. It fails to delete the downloaded installer.
I have placed the script in the location /usr/local/bin, filename blockelcapitan.sh and can also confirm that the launch dameon (stored in /Library/LaunchDaemons) is loaded as confirmed by using the command:
sudo launchctl list | grep net.
which shows a result of:
- 78 net.ORG.blockelcapitan
I need help with the script, I have no idea if it is correct or what needs adding/removing/changing.
#!/bin/bash
Version=$(sw_vers | grep ProductVersion | tail -c 7 | cut -d . -f 2)
if [[ $Version -ge 11 ]]
then
sudo launchctl unload /Library/LaunchDaemons/net.ORG.blockelcapitan.plist
sudo rm -rf /Library/LaunchDaemons/net.ORG.blockelcapitan.plist
sudo rm -rf /var/ORG/ElCapitan/
sudo rm -rf /var/db/receipts/net.ORG.pkg.BlockElCapitanLaunchDaemon.bom
sudo rm -rf /var/db/receipts/net.ORG.pkg.BlockElCapitanLaunchDaemon.plist
exit 0
fi
rm -rf /Applications/Install\ OS\ X\ El\ Capitan.app/
osascript -e 'display dialog "OS X El Capitan is not allowed on ORG computers at this time." with title "ORG Technology Notice" buttons {"OK"} default button "OK" giving up after 30'
Post-flight for installer PKG (you’ll want to use something like Packages for Mac to build a deployable .pkg):
#!/bin/bash
launchctl load -w /Library/LaunchDaemons/net.ORG.blockelcapitan.plist
Version=$(sw_vers | grep ProductVersion | tail -c 7 | cut -d . -f 2)
if [[ $Version -ge 11 ]]
then
sudo launchctl unload /Library/LaunchDaemons/net.ORG.blockelcapitan.plist
sudo rm -rf /Library/LaunchDaemons/net.ORG.blockelcapitan.plist
sudo rm -rf /var/ORG/ElCapitan/
sudo rm -rf /var/db/receipts/net.ORG.pkg.BlockElCapitanLaunchDaemon.bom
sudo rm -rf /var/db/receipts/net.ORG.pkg.BlockElCapitanLaunchDaemon.plist
exit 0
fi
Here is the actual launchdaemon itself:
Label
net.ORG.blockelcapitan
ProgramArguments
/usr/local/bin/blockelcapitan.sh
KeepAlive
PathState
/Applications/Install OS X El Capitan.app/
OnDemand
sql1
(1 rep)
Sep 6, 2016, 12:03 PM
• Last activity: Jul 10, 2025, 03:41 AM
1
votes
2
answers
47
views
Changing profiles on Terminal (macOS Mojave 10.14)
I'm unable to change my Terminal app profile (color theme) even when I change it in the preferences. I selected Homebrew as my profile, closed Terminal and reopened it - but it won't actually change to Homebrew. It shows the basic (default) profile. Is it possible that I have an issue with my .bash_...
I'm unable to change my Terminal app profile (color theme) even when I change it in the preferences. I selected Homebrew as my profile, closed Terminal and reopened it - but it won't actually change to Homebrew. It shows the basic (default) profile.
Is it possible that I have an issue with my .bash_profile, .bashrc, or .profile?
I'm trying to change it to the profile "Homebrew" seen below:

Oatmeal
(313 rep)
Jul 9, 2025, 03:35 AM
• Last activity: Jul 9, 2025, 03:14 PM
0
votes
2
answers
1368
views
Make backslash \ in terminal (Danish keyboard)
I am using a Danish keyboard language and Danish keyboard layout. When typing in my browser or other applications on my computer, I can make a backslash. In my case I use the combination shift + option + /. However, when I enter the terminal (either through VSC or directly from my computer), I can't...
I am using a Danish keyboard language and Danish keyboard layout. When typing in my browser or other applications on my computer, I can make a backslash. In my case I use the combination shift + option + /. However, when I enter the terminal (either through VSC or directly from my computer), I can't make backslash through the key combination. Nothing happens. I am using bash.
I have also tried the Z shell instead, but I can't make backslash there as well. For similar characters I can use their key combinations without any problems in the bash terminal. E.g. shift + option + ( makes an opening curly bracket '{'.
Thus, the key combination for backslash works fine in browser and applications, but not in the terminal. Is there a way to add a new key combination for the terminal?
morten
(1 rep)
Jun 5, 2024, 11:56 AM
• Last activity: Jul 1, 2025, 12:02 PM
1
votes
2
answers
117
views
Why does sh -version on my mac output the version of a bash shell?
I see sh -version GNU bash, version 3.2.57(1)-release (arm64-apple-darwin24) Copyright (C) 2007 Free Software Foundation, Inc. yet in https://developer.apple.com/library/archive/documentation/OpenSource/Conceptual/ShellScripting/shell_scripts/shell_scripts.html it mentions that `/bin/sh` is the Bour...
I see
sh -version
GNU bash, version 3.2.57(1)-release (arm64-apple-darwin24)
Copyright (C) 2007 Free Software Foundation, Inc.
yet in https://developer.apple.com/library/archive/documentation/OpenSource/Conceptual/ShellScripting/shell_scripts/shell_scripts.html
it mentions that
/bin/sh
is the Bourne Shell: *The first thing you should notice is that the script starts with ‘#!’. This is known as an interpreter line. If you don’t specify an interpreter line, the default is usually the Bourne shell (/bin/sh). However, it is best to specify this line anyway for consistency.*
I know in Linux /bin/sh points to the default shell, which defaults to Bash. but the apple script link is saying something else.
infoMining
(21 rep)
Jun 13, 2025, 07:48 PM
• Last activity: Jun 28, 2025, 08:04 PM
4
votes
3
answers
6938
views
cron lacks permissions to run a script
I have a script (which backs up, using `rclone`) that I run from the Terminal or Automator after `chmod a+x` with no permissions problems. When this script is run in cron (or `launchd`), stderr shows `"/bin/bash: /Users/joshua/script.sh: Operation not permitted."` This approach works fine in Ubuntu....
I have a script (which backs up, using
rclone
) that I run from the Terminal or Automator after chmod a+x
with no permissions problems.
When this script is run in cron (or launchd
), stderr shows "/bin/bash: /Users/joshua/script.sh: Operation not permitted."
This approach works fine in Ubuntu.
Edit: The above question remains relevant, but note that launchd
is the favored cron replacement for Mac, while Automator is available for application-level scheduling.
Joshua Fox
(1387 rep)
Nov 4, 2019, 10:42 AM
• Last activity: Jun 26, 2025, 02:07 AM
2
votes
1
answers
1494
views
Is it possible to close a script with a keypress?
In AutoHotKey, using the keyword "ExitApp" can allow the user to stop a script with a keypress. For example, `Esc::ExitApp` can stop a script by pressing "esc". Now, with a combination of `do shell script` (using a bash function like `read`) and `on idle` and then calling `exit` somehow, I thought t...
In AutoHotKey, using the keyword "ExitApp" can allow the user to stop a script with a keypress. For example,
Esc::ExitApp
can stop a script by pressing "esc".
Now, with a combination of do shell script
(using a bash function like read
) and on idle
and then calling exit
somehow, I thought this was possible in AppleScript. However, inside of an Automator function, you can't save an AppleScript as "stay open" - pasting the on idle
thing underneath on run
only loops through idle once without providing opportunities for listening for keypresses. Any ideas?
Example: Let's say I have this script in an automator workflow:
on run {input, parameters}
set i to 0
repeat while i < 100
keystroke "a"
set i to i + 1
delay 5
end repeat
end run
Aaron
(33 rep)
May 7, 2021, 07:26 PM
• Last activity: Jun 17, 2025, 02:03 PM
13
votes
4
answers
3857
views
Where can I find all the documentation for mac's builtin shell commands?
The [`builtin` man page for Mac OS X](https://web.archive.org/web/20040709220105/http://developer.apple.com/documentation/Darwin/Reference/ManPages/html/builtins.1.html) lists out all builtin functions (commands that can be executed within the running shell's process). But where can I find the docum...
The [
builtin
man page for Mac OS X](https://web.archive.org/web/20040709220105/http://developer.apple.com/documentation/Darwin/Reference/ManPages/html/builtins.1.html) lists out all builtin functions (commands that can be executed within the running shell's process).
But where can I find the documentation of a particular one?
For instance, for the builtin fc
on Ubuntu Linux, I can get its help by:
> help fc
fc: fc [-e ename] [-lnr] [first] [last] or fc -s [pat=rep] [command]
Display or execute commands from the history list.
fc is used to list or edit and re-execute commands from the history list.
FIRST and LAST can be numbers specifying the range, or FIRST can be a
string, which means the most recent command beginning with that
string.
....
Another example is the if
expression, on Ubuntu:
> help if
if: if COMMANDS; then COMMANDS; [ elif COMMANDS; then COMMANDS; ]... [ else COMMANDS; ] fi
Execute commands based on conditional.
...
What am I missing here?
user2829759
(241 rep)
Feb 21, 2017, 06:05 AM
• Last activity: May 16, 2025, 05:42 AM
1
votes
1
answers
477
views
/etc/ppp/ip-up file is not being called upon VPN creation; Monterey
I'm trying to add certain subnets to my route table after launching an IKEv2 VPN tunnel from my Mac. I understand that this behaviour can be achieved by placing an executable `ip-up` file in `/etc/ppp/` folder. File perms are correct it has 0755 and root is the owner, however upon firing up the VPN...
I'm trying to add certain subnets to my route table after launching an IKEv2 VPN tunnel from my Mac. I understand that this behaviour can be achieved by placing an executable
ip-up
file in /etc/ppp/
folder.
File perms are correct it has 0755 and root is the owner, however upon firing up the VPN tunnel the route is not being added. I suspect the file is not being called?
Contents of the ip-up
file:
#!/bin/sh
/sbin/route add -net 192.168.66.0/24 -interface $1
I'm running Monterey 12.2.1
vboxer00
(11 rep)
Mar 27, 2023, 05:16 PM
• Last activity: May 2, 2025, 11:01 PM
44
votes
8
answers
87742
views
How to set system-wide environment variables
We used to use `/etc/environment` to set system-wide environment variables on Mountain Lion. However, it seems this file is no longer read. Ideally the solution should apply to all users, and we need it to work with ssh console sessions. So we need this to work ssh user@mavericks-machine 'echo $MY_E...
We used to use
/etc/environment
to set system-wide environment variables on Mountain Lion. However, it seems this file is no longer read.
Ideally the solution should apply to all users, and we need it to work with ssh console sessions. So we need this to work
ssh user@mavericks-machine 'echo $MY_ENV_VAR'
So far we've tried:
- /etc/launchd.conf
Works for all users, but only applies to 'windowed' applications, i.e. works in Terminal, but not in an ssh session.
- ~/.profile
, ~/.bash_profile
etc.
Only applies to shells
Any suggestions?
joerick
(828 rep)
Oct 31, 2013, 02:41 PM
• Last activity: May 2, 2025, 10:04 AM
2
votes
1
answers
204
views
Possible diskutil info protocol fields?
Is there somewhere in the OS such as a `plist` that stores all the possible protocols for `diskutil info`? So far, I have come across the internal disks as PCI, SATA and PCI-Express. ``` diskutil info /dev/disk0 Device Identifier: disk0 Device Node: /dev/disk0 Whole: Yes Part of Whole: disk0 Device...
Is there somewhere in the OS such as a
plist
that stores all the possible protocols for diskutil info
? So far, I have come across the internal disks as PCI, SATA and PCI-Express.
diskutil info /dev/disk0
Device Identifier: disk0
Device Node: /dev/disk0
Whole: Yes
Part of Whole: disk0
Device / Media Name: APPLE SSD AP0512N
Volume Name: Not applicable (no file system)
Mounted: Not applicable (no file system)
File System: None
Content (IOContent): GUID_partition_scheme
OS Can Be Installed: No
Media Type: Generic
Protocol: PCI-Express
SMART Status: Verified
Bob R
(147 rep)
Sep 6, 2023, 11:38 PM
• Last activity: May 2, 2025, 03:07 AM
4
votes
1
answers
353
views
Using command line to switch On/Off IPv4 or IPv6 network on macOS
I'm looking for a way to switch On/Off IPv4 or IPv6 network from command line on macOS. Like the description here: https://apple.stackexchange.com/questions/7931/can-i-turn-off-ipv4-and-just-use-ipv6-on-my-mac one can turn On/Off IPv4 on macOS using the GUI. However, I'm trying to manage multiple Ma...
I'm looking for a way to switch On/Off IPv4 or IPv6 network from command line on macOS.
Like the description here:
https://apple.stackexchange.com/questions/7931/can-i-turn-off-ipv4-and-just-use-ipv6-on-my-mac
one can turn On/Off IPv4 on macOS using the GUI.
However, I'm trying to manage multiple Mac mini remotely, and therefore, would like to do the task from command line.
In my case particularly, I'm able to access the macOS client via VNC viewer, which only support IPv4. Therefore, after disable the IPv4 from GUI via VNC session, I only have access to the client via IPv6 by using SSH. So, if this cannot be done via command line, I'll not able to recover the IPv4 unless I have access to that machine locally.
So, I am looking forward for the command line that I can use to enable IPv4 on Mac, or even further, switch On/Off IPv6 network as well.
Weishan Yang
(145 rep)
Apr 30, 2025, 09:46 AM
• Last activity: May 1, 2025, 03:24 PM
9
votes
1
answers
1936
views
Change keyboard layout automatically when external keyboard connected
I recently purchased an external keyboard (non-apple) that is used at home and also dragged along with me from time to time, and I've noticed a need. My Mac is in English, as well as its physical keyboard. However, my external keyboard is in Norwegian. I am finding it quite cumbersome to have to swa...
I recently purchased an external keyboard (non-apple) that is used at home and also dragged along with me from time to time, and I've noticed a need.
My Mac is in English, as well as its physical keyboard. However, my external keyboard is in Norwegian.
I am finding it quite cumbersome to have to swap the keyboard layout every time i swap keyboard, which can be quite often. I noticed that the keyboard layout can change according to the app being used, but this doesn't always work.
**Is it possible to make the Mac change its keyboard layout either based on the current keyboard being used or every time I either plug on unplug the external keyboard?**
**Something I've already tried**
I've created an AppleScript that sort of solves this, but ran into some problems with Mojave and its security, and therefore wondering if I should approach this differently. I'll attach the script for reference, we might have to just alter it if there isn't a better solution..
Would appreciate any thoughts at all.
Problem I'm running into is that the app is not allowed to send keystrokes via system events, even though I've permitted it in System Preferences.
--Checks connected usb devices for description, performs keypresses if condition is met
set devicePresent to false
set changeLayout to false
delay 2 --delay may not be needed. To make sure that usb device is registred before script is triggered
set currentLayout to do shell script "defaults read ~/Library/Preferences/com.apple.HIToolbox.plist AppleSelectedInputSources | egrep -w 'KeyboardLayout Name' | cut -d '=' -f2;exit "
set USB to paragraphs of (do shell script "system_profiler SPUSBDataType -detailLevel basic")
repeat with i from 1 to (count of USB)
if item i of USB contains "Product ID: 0x0059" then set devicePresent to true
end repeat
if (devicePresent) then
if currentLayout contains "ABC" then set changeLayout to true --changes layout to norwegian
end if
if (not devicePresent) then
if currentLayout contains "Norwegian" then set changeLayout to true --changes layout to english
end if
if (changeLayout) then tell application "System Events"
key code 49 using control down
set newLayout to do shell script "defaults read ~/Library/Preferences/com.apple.HIToolbox.plist AppleSelectedInputSources | egrep -w 'KeyboardLayout Name' | cut -d '=' -f2;exit "
display notification ("Changed layout from " & currentLayout & " to " & newLayout) with title "New Layout" sound name "Sound Name"
end tell
hpl002
(191 rep)
Jan 5, 2019, 10:39 PM
• Last activity: Apr 10, 2025, 04:07 AM
4
votes
2
answers
253
views
Side effects of changing the default shell in macOS to a Homebrew location
Some people prefer the latest Bash version for macOS (because `/bin/bash` is still a version in the 3.x range). This can be changed with this: ``` brew install bash chsh -s /opt/homebrew/bin/bash ``` **However**, what are the implications and possible complications of using a path that is user writa...
Some people prefer the latest Bash version for macOS (because
/bin/bash
is still a version in the 3.x range).
This can be changed with this:
brew install bash
chsh -s /opt/homebrew/bin/bash
**However**, what are the implications and possible complications of using a path that is user writable and potentially vulnerable to corruption, such as
- accidental deletion of the referenced login shell,
- destruction of the /opt/homebrew/bin/bash
symlink, which normally points to a specific version of bash,
- malicious software that may exchange the symlink and replace it with a Bitcoin miner
etc.
dersimn
(351 rep)
Mar 24, 2025, 11:27 AM
• Last activity: Mar 24, 2025, 09:48 PM
1
votes
2
answers
159
views
Cannot get zsh to resemble bash_profile with xterm Linux colors for MacOS
I installed a new logic board and thought I had to reinstall MacOS, so I upgraded to the final release of Big Sur. I've realized the bash shell is no longer being used, and now MacOS is using zsh, and simply editing my bash_profile file. This is one reason why I don't like upgrading to newer OS's, b...
I installed a new logic board and thought I had to reinstall MacOS, so I upgraded to the final release of Big Sur.
I've realized the bash shell is no longer being used, and now MacOS is using zsh, and simply editing my bash_profile file. This is one reason why I don't like upgrading to newer OS's, but can also no longer remain on Mojave for multiple reasons.
My attempts:
1. Since nano ~/.bash_profile is no longer being looked at by MacOS, I've tried simply updating zsh_profile, .zprofile, and .profile with my original commands that were exactly what I wanted for my profile: export CLICOLOR=1 export LSCOLORS=GxFxCxDxBxegedabagaced and unfortunately this has done nothing after properly saving, confirmed the save state, exiting and restarting the computer each time with no change.
2. Additionally, I did open ~/.zshrc and added the export commands along with the following conditional command:
if [ -f ~/.bash_profile ]; then
. ~/.bash_profile;
fi
which was in a thread from Stack Overflow, but this did not work either.
3. I also went into my Terminal Preferences and under the General settings, changed my 'Shell open with' from the Default login shell to 'Command (complete path) /bin/bash but this changed nothing even when I made sure my bash_profile is also updated on this new installation of Big Sur.
4. When clicking 'Profiles' and selecting the Advanced tab, I've declared terminal as xterm hoping this would also update my main color scheme, but no.
5. I "brute forced" the colors by altering the ANSI colors from magenta and cyan to red and blue which partially worked for the terminal, but then when I verified what Vim looked like afterward, it obviously inverted my colors which I do not like. So I switched the ANSI colors back. I have Vim exactly as I want it for traditional Linux highlighting.
I could technically switch the ANSI colors back in Terminal Preferences again and just alter my highlighting LineNr, ctermfg and Tagname colors in my ~/.vimrc file, but I really don't feel like I should have to make those kind of alterations. I would much prefer to get the system to just properly see my zsh color scheme to classic Linux xterm colors.
I cannot stand the zsh color scheme and just want the old bash highlighting theme, but as mentioned, I can no longer use Mojave, and Monterey has a bad reputation for eating through batteries. I also replaced my old battery with a brand new one and everyone seems to like the final release of Big Sur, rather than upgrading to the latest OS's.
How can I change zsh to be like bash used to work?
cjordan
(5 rep)
Dec 19, 2024, 08:20 PM
• Last activity: Mar 16, 2025, 10:01 AM
1
votes
1
answers
1534
views
How do I copy multiple files to macOS's clipboard programmatically?
I ultimately want to have a bash function `to-clipboard` which gets file paths and copies the files to the clipboard. Using other scripting languages as helpers is okay. I currently have this for copying a single file: file-to-clipboard() { osascript \ -e 'on run args' \ -e 'set the clipboard to POS...
I ultimately want to have a bash function
to-clipboard
which gets file paths and copies the files to the clipboard. Using other scripting languages as helpers is okay. I currently have this for copying a single file:
file-to-clipboard() {
osascript \
-e 'on run args' \
-e 'set the clipboard to POSIX file (first item of args)' \
-e end \
"$@"
}
There is this Applescript that supposedly can copy multiple files, but I don't like it at all:
set f to {(POSIX file "/path/to/a/folder/a.png"), (POSIX file "/path/to/another/folder/b.png")}
tell application "Finder"
try -- to delete any old temp folder
delete folder "AS_mailCopy" of (path to temporary items)
end try
set tmp to make new folder at (path to temporary items) with properties {name:"AS_mailCopy"}
duplicate f to tmp
select files of tmp
activate
tell application "System Events" to keystroke "c" using command down
delete tmp
end tell
Related question:
https://apple.stackexchange.com/questions/66459/copying-files-to-the-clipboard-using-applescript
HappyFace
(712 rep)
Oct 10, 2018, 04:47 PM
• Last activity: Mar 15, 2025, 02:10 PM
0
votes
0
answers
31
views
Terminal / Bash: Permission denied when appending to a file with RW rights granted by ACL
I have a file "test.log" inside a directory. The directory has an accesslist, defined as: 0: user:Me allow list,add_file,delete_child,file_inherit The file "test.log" (created by root) has automatically the following access rights: -rw-r--r--+ 1 root wheel 0: user:Me inherited allow read,write As "M...
I have a file "test.log" inside a directory.
The directory has an accesslist, defined as:
0: user:Me allow list,add_file,delete_child,file_inherit
The file "test.log" (created by root) has automatically the following access rights:
-rw-r--r--+ 1 root wheel
0: user:Me inherited allow read,write
As "Me", I can open this file in Terminal – for example with nano – edit it, save the changes and exit nano.
Result: the file has been changed as expected.
When I use the following command:
echo "test" >> test.log
I get the error:
-bash: test.log: Permission denied
"Me" is a standard user.
When I
su
to an admin user, the admin user gets the same Permission denied error when executing echo "test" >> test.log
.
Even, as admin user, when I use sudo echo "test" >> test.log
I also get the Permission denied error. Only as root can I append text to the file using echo >>
.
I have no idea, how to fix that or what causes this behaviour.
CreaTurE
(31 rep)
Mar 12, 2025, 06:06 PM
• Last activity: Mar 12, 2025, 08:36 PM
Showing page 1 of 20 total questions