Results 1 to 5 of 5

Thread: How can I create shell script which find out who the active, current user is?

  1. #1
    Join Date
    Oct 2010
    Posts
    103

    How can I create shell script which find out who the active, current user is?

    I am attempting to make a shell script for my Mac, that does the following:

    1. It should runs each 20 seconds
    2. It should checks to observe if a user is logged in and active
    3. It should also captures a screenshot of that user's desktop and saves it to disk


    How to make the script which run each 20 seconds by utilizing launch ctl along with a plist file. The plist file utilizes the Start Interval key with a worth of 20, thus call upon it each 20 seconds. I overloaded the job as root with the command "sudo launchtl load $path_to_plist_file", then "sudo load $name_of_job".
    And also I have figured out that how to confine a screenshot with a script. Because the script is running AS root but it is not gripping or you say that it is not able to grab the screenshot for root, according to the screen capture page I have to utilize the command "sudo launchctl bsexec $PID screencapture" I have checked this and it works, but it will work only if I know the PID of the current user. Here is the problem because I do not know that how to get the PID of the user. So please help me in this. If you know that how to script which can check the user is logged in with their desktop active on the monitor?

  2. #2
    Join Date
    Apr 2008
    Posts
    4,642

    Re: How can I create shell script which find out who the active, current user is?

    It’s a custom script that make sure a server to decide if the laptop is stolen, and send data if it is required. I also wanted to do the similar thing, and I have ended up resolving it by utilizing a small AppleScript magic. I did not even believe to look at the screen capture man page. Mainly, I have formed an AppleScript with the following contents:
    Code:
    set cmd to "/usr/sbin/screencapture -x -tjpg /tmp/screen.jpg > /dev/null 2>&1"
    do shell script cmd
    Of course you are able to modify the screen capture choices and the path of the resultant image file if you desire. So you just do this in to the Script Editor and after it save this as an application bundle, with none of the options checked.

  3. #3
    Join Date
    May 2008
    Posts
    4,570

    Re: How can I create shell script which find out who the active, current user is?

    You almost certainly desire to create it a background application so the user does not become aware of the script initiation. To do this, you just go to the application bundle in Finder, right-tap on it and demonstrate Package Contents, then go to Contents and open Info.plist along with TextEdit. Just on top of the line with <key>WindowState</key> insert the following:
    Code:
    <key>NSUIElement</key>
    	<string>1</string>
    At last, in your most important shell script, call this with "open /path/to/AppleScriptBundle.app". And after it open it as the current logged-in user without you having to presume who that is. With any luck I think this will help. I assume the only thing it does not do is make sure whether somebody is really active on the machine.
    Last edited by Glenny; 20-10-2010 at 11:58 AM.

  4. #4
    Join Date
    May 2008
    Posts
    4,345

    Re: How can I create shell script which find out who the active, current user is?

    But here I want to ask you that, I am currently running a shell script by using the launchctl, and I have observed that it is not opening it as the current logged-in user, It is running this as a root the reason behind this that I have initiated it with the command "launchctl start $job_name". but actually this provides me n a superb idea, am I able to set launchctl to run the script as the current logged-in user? Hey thanks for your idea but you have solution of this then please reply me.

  5. #5
    Join Date
    May 2008
    Posts
    4,831

    Re: How can I create shell script which find out who the active, current user is?

    If you run cron through my script, which in OS X is efficiently launched by launchctl. Currently I am running this as the root. When root runs the open command then the resulting application runs as the presently logged-in user. You are also able to attempt it: just type the ssh in to the command and run somewhat like "sudo open /Applications/iTunes.app". Even supposing "open" runs as the root, and also iTunes will begin as the logged-in user. This is accurately the situation you would like for running screen capture. I would not have recommended that answer if it did not work for me.

Similar Threads

  1. User account picture via script and create and share
    By venkat=raghavan in forum Software Development
    Replies: 6
    Last Post: 09-12-2010, 07:06 AM
  2. Linux shell script to find duplicate images
    By Savious in forum Operating Systems
    Replies: 6
    Last Post: 21-10-2010, 05:26 AM
  3. Selecting a user in a shell script
    By Quattro in forum Operating Systems
    Replies: 5
    Last Post: 25-12-2009, 02:11 PM
  4. how to find out object type(user,computer,group) in active directory?
    By vivekmohan in forum Software Development
    Replies: 2
    Last Post: 06-08-2009, 04:19 PM
  5. How can I find out who created a user account in Active Directory
    By bubblecrumb in forum Windows Server Help
    Replies: 0
    Last Post: 13-02-2008, 02:00 PM

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Page generated in 1,714,045,819.15981 seconds with 17 queries