robmathers / WhereAmI

A quick command line tool for OS X to get your geographic coordinates using the CoreLocation framework.
MIT License
197 stars 20 forks source link

Automation issues #10

Open pwmurf opened 2 years ago

pwmurf commented 2 years ago

Hi there,

We're trying to deploy whereami in a script that is run on an interval using launchd and for some reason it can't execute it in this environment. The same is true when trying to run it using cron. We can run it manually in the CLI all day (both the utility and the script containing it) but we've had no success using the native macOS automation tools. Here's an example of the plist we've been using:

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
    <dict>
        <key>Label</key>
        <string>org.metroeast.whereami</string>
        <key>ProgramArguments</key>
        <array>
                 <string>/usr/local/bin/whereami</string>
                </array>
        <key>RunAtLoad</key>
        <true/>
        <key>StartInterval</key>
        <integer>3600</integer>
                 <key>StandardOutPath</key>
                 <string>/tmp/whereami.now</string>
                 <key>StandardErrorPath</key>
                <string>/tmp/whereami.now</string>
    </dict>
</plist>

We tested the date utility in the same launchd file to make sure it would run something else and it did. Any ideas?

robmathers commented 2 years ago

Just a guess, but I think you need to use the Program key for the executable path. The ProgramArguments would be any flags afterwards.

Otherwise, I haven't tried using launchd for it, but my recollection with other things is you need to be pretty careful about paths and permissions, since the environment isn't the same as when you run it from a shell.

One other thought is to try and run a shell script that calls the executable and see if that gives any more output you could debug with.

elkram commented 2 years ago

We found that we can execute whereami, by first determining the current logged user, and prefixing with sudo, like so: logged_user=$(/bin/ls -l /dev/console | /usr/bin/awk '{ print $3 }') this_location=$(sudo -u "$logged_user" /usr/local/bin/whereami)

pwmurf commented 5 months ago

Hello again...

After updating to Sonoma I'm noticing that whereami doesn't present itself under Sys Pref > Privacy & Security > Location Services anymore. Invoking it in the CLI doesn't ask for permission anymore, it just alerts you that you need to grant it. I don't see a way to add apps manually in Sonoma.

Access to location services was denied. You may need to enable access in System Preferences.
pwmurf commented 5 months ago

Never mind, I see this was brought up in a separate issue!