![]() |
screen capture package
Well,
I have been kind of asked to look into creating a package that will take screen shots every so often. So I want to do it with built in tools, but I have not really ever developed something into an application before for OS X. I am looking at the screenshot binary in /usr/sbin/screencapture so this will be easy to script out. However, the documentation is really lacking. So I would like to make some sort of installer, probably in a pkg that installs a script, and then sets a launchd item to run the script every 15 minutes (just tossing that number out there) and then starts logging screen shots into a specific folder that I choose. This seems easy to do, but like I said, I have never really wrapped up launchd items and shell scripts into a package before, so I guess I may need some hand holding - you know in a completely platonic way of course :eek: Also, if there is a better way to implement this other than creating a launchd item that runs a few liner script every so often and then dumps the screen shots in a specific folder let me know, I would love to hear it. I think I would like the installer to allow the person installing it to also choose the output directory to which these screen shots are saved. There is a product that does this, but it is like $40 per a license and well we have 6,000 macbooks and we aren't going to spend $40 x 6,000 for something like this when I can just write it myself. Thanks in advance for any and all help~! tom |
I think that creating a launchd item that runs a script which uses the screencapture executable is the way to go. I can't think of a better way. Here's how I would implement it.
The easiest way to make an installer application is by writing an applescript application. Any files you need to install you just embed inside of the app, and then use applescript commands to copy them into the proper locations. For example, if you put your script in the Contents/Resources folder of the applescript then you can do the following in the applescript. 1. Create a folder inside the application support folder to hold anything you install (like the script) Code:
set appFolderName to "myProgramName"Code:
set scriptPath to (path to me as text) & "Contents:Resources:myScriptName"Code:
set textFileName to "textFile.txt"http://macscripter.net/viewtopic.php?id=20949 |
Thanks for your help, yes I want to do it all via shell scripts and launchd
I also want to create an uninstaller that will wipe out what is installed as this will be installed on a case by case basis. Also since this is a case by case basis it will probably be needed to be added into /Library/Launchagents so it can run when a user logs in, and it will probably require a reboot... I found this link kind of explaining the deployment of packages through installers http://www.osxgnu.org/info/osxpackages.html I haven't had a chance to read up on it yet, been too busy at work today making packages.. |
Maybe you're not too familiar with writing applescripts so you should probably stick with what you found. I gave you virtually all the applescript code you would need so you just need to put it together in one app. And if you also want it to be an uninstaller then you would just pop up a dialog box at launch of the applescript asking if the user wanted to install or uninstall stuff... and then go from there. But again, what seems easy to me isn't what's easy for you. However, if you decide to pursue the applescript methodology I'll be around to help more.
|
Really slick, Hank.
|
Quote:
However, I cannot have the end user see any of this. I work at a school district with a 1:1 program so every high school kid has a macbook. Some of the administration people want to be able to install this on kids who are causing problems with the laptops and they want to be able to produce evidence. As these kids are smart, they like to delete their data when they are about to get caught. One of the educational side people found this program that is 40 bucks a pop that takes screen shots every so often and runs in the background. Well, when I was poking around in BASH I saw there was built in binary so why pay for something that I can probably build myself. Thank you for all your help, and once I get CS4 packaged and began pushing it out this is my next project to tackle. So hopefully, starting next week I will have the basics down. Thanks again Tom |
Well I got the beta script running, it is quite simple:
Code:
#!/bin/bashSo I want the installer to install the script in /Library/Scripts/Screens/screenshot.sh for example, then I want it to make a folder called "screen shots" in the desired path the installer chooses, and then also let the person insalling the package set the name variable. Then I want that installer to create a new package with all that information they input so they can deploy it. Then the installer will deploy the launchd item, create the directories to store the file in it, it will also launch the plist file via launchctl and then set the permissions and ownerships to all items installed to root:admin 770 so only admin and root can access them. Then make a script that will uninstall everything that I just did in case they want to take it off. I also want to make the interval of the screen shots set up the initial installer. So it will pump out how often the launchd item runs. I want to keep it as simple as possible with the least amount of code as possible. I think if it all works out I will publish it for free off my site. Thoughts? |
Quote:
Quote:
Quote:
Quote:
You have most of the installer code if you decide to use the applescript technique. If you go that route, put it together and post the code and I'll help you with anything you're still missing. |
Thank you very much for your help. I will try to mess around with it this weekend...
I am a Linux/Unix guy so I love using shell when I can, and I am a bit new to Apple Script but not afraid to give it a whirl. I will try some of this code, but I guess I am kind of not totally grasping how to wrap it all up in an application? |
Any shell commands you need to run, for example you want to set root:admin 770, you can do via applescript using:
do shell script "the shell command" After you write the applescript code, just save the applescript as an applescript application bundle. An application bundle creates a universal binary application that will run natively on both PPC and Intel macs. You can right-click on that to show package contents in the Finder and manually place the screen capture script inside of the Contents/Resources folder and then you'll have a complete installer application. |
Quote:
Thanks again |
Quote:
|
Quote:
I am thinking down the road how to easily change things on the fly and be able to deploy the package over the network, since this is for my 6,000 mac laptops and about 3,000 ish mac desktops at the school district I work for. Thanks again for all your help |
Since I showed you how to write a text file, you could create everything on-the-fly. In other words the installer could get the variables as I showed with the dialog boxes, create the code for the screen capture script using those variables, then write the screen capture script to disk as a text file all with the variables included in the generated script. Then use do shell script commands to turn that text file into a unix executable file, and run it using launchd. This would eliminate the need to embed the screen capture script with the installer and would also eliminate the need for the text file to hold the variables.
Try this. Save this code into script editor and run it. It will ask you for the input variables, create the shell script on your desktop, and make the shell script executable. It will demonstrate what I mean. Code:
-- get the input information for the script |
This is great stuff, Hank. Be the making for a really good tutorial.
Adam |
WOW
Thank you a lot! I edited the script to change some things around I think I want the short name in the file name. I was just told this could be used as evidence in court from one of the higher ups and I guess they want to cut down on gang activity... This should turn out to be a fun project. I am learning stuff on this one. thanks Tom |
Quote:
Glad to help Tom. Applescript is really powerful in that you can do almost anything with it. When combined with being able to execute shell commands it's limitless. Now you just have to look into my #4 above to incorporate the launchd stuff and polish up the code a little. |
I see what you mean, and it did work, but how do I wrap all that info up into an actual application after the user sets those things. This can be ran as a PKG file I assume?
I also still need to create the launchd item, then load it, then force a reboot so it runs at start. |
I saved the script as an application and it does ask for user input, how do I input that info into an existing package so it edits those contents and then can just be ran and installs the script, and the launchd item?
I am going to read through some of the developer white pages this week to see what to do. I think the apple script is pretty sweet though. |
There's an applescript forum where you can get help specifically on applescript. It sounds like you need more help than I can give you by myself, so post your questions there.
http://macscripter.net/viewforum.php?id=2 If you want to learn more about applescript that website has tutorials. Go here to search the forums and search for "applescript for beginners". These tutorials are short and will teach you the basics. It's how I learned applescript. http://macscripter.net/search.php |
Quote:
-Tom |
Oh and I had to edit my script, it seems that the binary logname only captures what user is running the current process and if installed via ARD admin it will log it as root user, so I had to change that variable, here it is:
Code:
#!/bin/bash |
| All times are GMT -5. The time now is 05:35 AM. |
Powered by vBulletin® Version 3.8.7
Copyright ©2000 - 2014, vBulletin Solutions, Inc.
Site design © IDG Consumer & SMB; individuals retain copyright of their postings
but consent to the possible use of their material in other areas of IDG Consumer & SMB.