New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[bug] Hammerspoon (and forked child processes) can't see files in /Applications
when launched as a Login Item
#3599
Comments
So I've noticed that this happens the very first time this function ( |
I refactored my Spoon over the weekend to avoid the hang and I think I have an idea of what's causing it. It seems that when Hammerspoon is a Login Item, it's coming up in such a way that it's not able to find app bundles in
However, shelling out manually from a terminal application shows no issues: $ 1>/Users/dougstephen/.hammerspoon/Spoons/Visor.spoon/kitty/kitty_daemon.out 2>/Users/dougstephen/.hammerspoon/Spoons/Visor.spoon/kitty/kitty_daemon.err nohup kitty -d $HOME -1 --instance-group KITTY_HOTKEY_WINDOW -T KITTY_HOTKEY_WINDOW --listen-on unix:/Users/dougstephen/.hammerspoon/Spoons/Visor.spoon/kitty/socket -c /Users/dougstephen/.hammerspoon/Spoons/Visor.spoon/kitty/visor_window.conf false &
[1] 7337
$ ps aux | grep kitty
dougstephen 7391 0.0 0.0 33728048 660 s002 R+ 9:28AM 0:00.00 grep --color=auto --exclude-dir=.bzr --exclude-dir=CVS --exclude-dir=.git --exclude-dir=.hg --exclude-dir=.svn --exclude-dir=.idea --exclude-dir=.tox kitty
dougstephen 7337 0.0 0.2 34929352 80896 s002 SN 9:28AM 0:00.72 /Applications/kitty.app/Contents/MacOS/kitty -d /Users/dougstephen -1 --instance-group KITTY_HOTKEY_WINDOW -T KITTY_HOTKEY_WINDOW --listen-on unix:/Users/dougstephen/.hammerspoon/Spoons/Visor.spoon/kitty/socket -c /Users/dougstephen/.hammerspoon/Spoons/Visor.spoon/kitty/visor_window.conf false
root 7095 0.0 0.0 34291264 4008 s000 Ss 9:27AM 0:00.02 /usr/bin/login -f -l -p dougstephen /Applications/kitty.app/Contents/MacOS/kitten run-shell --shell /bin/zsh --shell-integration no-cursor --cwd=/Users/dougstephen
dougstephen 7094 0.0 0.3 35969248 97904 ?? S 9:27AM 0:01.62 /Applications/kitty.app/Contents/MacOS/kitty And then after quitting and re-launching Hammerspoon, everything works fine. |
hs.application.applicationsForBundleID
/Applications
when launched as a Login Item
Hmm… It looks to me like that error message is actually
I'm not sure where you have the Just to make sure, though, next time Hammerspoon starts as a login item and is failing to run the print(hs.execute [[ls /Applications]])
-- and/or
print('[[[')
for file in hs.fs.dir('/Applications') do
print('\t' .. file)
end
print(']]]') and see if it can see the apps that way? |
@Rhys-T I'll try that and get back to you with the output! As a few more points of clarification: It's expecting a Additionally, it was failing before the |
@Rhys-T The files are there. The more I spend time with it, the more I'm starting to think that the issue is related to the environment. I'm going to go out on a limb and guess that macOS Login Items don't inherit the user's typical login environment and things like their This hunch is further corroborated by the fact that if I use |
Hammerspoon (in fact all MacOS application bundles) do not inherit any path or environment variables set by the traditional shell init scripts. I haven't read the whole thread (I will tomorrow, but this caught my eye right before heading off to bed), but since I have noticed you're using Try doing |
I know it doesn't take the interactive login stuff like Forcing it to inherit the user environment might work. I'd like to find a way to make it work as a login item the same way it works otherwise if possible, though, because of this note in the docs:
I'll try it out though as it's a good baseline I could use to start from if it does fix things. |
@Rhys-T @asmagill I added the following to my print(
string.format(
"\n'$0': %s\n'$SHELL': %s\nShell options: %s\nShell env: %s\n",
hs.execute([[echo $0]]),
hs.execute([[echo $SHELL]]),
hs.execute([[echo $-]]),
hs.execute([[( setopt posixbuiltin; set; )]])
)
) I've made a zip with the two outputs. The shell options are the same, but for whatever reason, the |
One last update: I changed all the shellouts to use absolute paths and I no longer see the issue with |
So I did a much more thorough audit of my setup, and after making sure I made everything absolute paths in both the spoon and my wrapper scripts, the issue has gone away. Meaning: it seems that the other stuff related to app bundles was a red herring. The larger issue was the one in my previous comment, which is that the |
Environment
OS: macOS Sonoma (encountered on 14.1.x, 14.2.x, and 14.3.x)
Arch: Intel
Hammerspoon Version: Version 0.9.100 (6815)
Bug Report
I recently developed a Spoon for myself and I noticed that sometimes it hangs on loading of my config. Activity Monitor shows very high CPU usage and very high virtual memory usage in this situation. I saw a virtual RAM usage of over 40 GB on a cold boot of my MBP with ~100% CPU.
I dug in to
Console.app
and found a Diagnostic Report that captured the heaviest stack, and it seems to be related tohs.application.applicationsForBundleID
:Captured Heavy Stack
Here's the entire diagnostic report: Hammerspoon_2024-02-07-092250_marvin.cpu_resource.diag.zip
The Spoon in question (and the issue on the Spoon for tracking this): dljsjr/Visor.spoon#1
The text was updated successfully, but these errors were encountered: