From 07edebe011f3a17d0113e4f34b537e9e3e725a2a Mon Sep 17 00:00:00 2001 From: Filipp Lepalaan Date: Tue, 2 Feb 2016 11:47:15 +0200 Subject: Initial commit --- README.md | 45 +++++++++++++++ Troublegun.app/Contents/Info.plist | 48 ++++++++++++++++ Troublegun.app/Contents/MacOS/applet | Bin 0 -> 25028 bytes Troublegun.app/Contents/PkgInfo | 1 + .../Contents/Resources/Scripts/main.scpt | Bin 0 -> 584 bytes Troublegun.app/Contents/Resources/applet.icns | Bin 0 -> 71867 bytes Troublegun.app/Contents/Resources/applet.rsrc | Bin 0 -> 362 bytes Troublegun.app/Contents/Resources/config.ini | 7 +++ .../Contents/Resources/description.rtfd/TXT.rtf | 4 ++ Troublegun.app/Contents/Resources/entourage.scpt | 6 ++ Troublegun.app/Contents/Resources/gethelper.sh | 1 + Troublegun.app/Contents/Resources/mail.scpt | 10 ++++ Troublegun.app/Contents/Resources/main.py | 62 +++++++++++++++++++++ Troublegun.scptd/Contents/Info.plist | 27 +++++++++ .../Contents/Resources/Scripts/main.scpt | Bin 0 -> 1128 bytes Troublegun.scptd/Contents/Resources/config.ini | 8 +++ .../Contents/Resources/description.rtfd/TXT.rtf | 4 ++ Troublegun.scptd/Contents/Resources/entourage.scpt | 6 ++ Troublegun.scptd/Contents/Resources/gethelper.sh | 1 + Troublegun.scptd/Contents/Resources/mail.scpt | 10 ++++ Troublegun.scptd/Contents/Resources/main.py | 62 +++++++++++++++++++++ 21 files changed, 302 insertions(+) create mode 100644 README.md create mode 100644 Troublegun.app/Contents/Info.plist create mode 100755 Troublegun.app/Contents/MacOS/applet create mode 100644 Troublegun.app/Contents/PkgInfo create mode 100644 Troublegun.app/Contents/Resources/Scripts/main.scpt create mode 100644 Troublegun.app/Contents/Resources/applet.icns create mode 100644 Troublegun.app/Contents/Resources/applet.rsrc create mode 100644 Troublegun.app/Contents/Resources/config.ini create mode 100644 Troublegun.app/Contents/Resources/description.rtfd/TXT.rtf create mode 100644 Troublegun.app/Contents/Resources/entourage.scpt create mode 100644 Troublegun.app/Contents/Resources/gethelper.sh create mode 100644 Troublegun.app/Contents/Resources/mail.scpt create mode 100755 Troublegun.app/Contents/Resources/main.py create mode 100644 Troublegun.scptd/Contents/Info.plist create mode 100644 Troublegun.scptd/Contents/Resources/Scripts/main.scpt create mode 100644 Troublegun.scptd/Contents/Resources/config.ini create mode 100644 Troublegun.scptd/Contents/Resources/description.rtfd/TXT.rtf create mode 100644 Troublegun.scptd/Contents/Resources/entourage.scpt create mode 100644 Troublegun.scptd/Contents/Resources/gethelper.sh create mode 100644 Troublegun.scptd/Contents/Resources/mail.scpt create mode 100755 Troublegun.scptd/Contents/Resources/main.py diff --git a/README.md b/README.md new file mode 100644 index 0000000..a5b5b5a --- /dev/null +++ b/README.md @@ -0,0 +1,45 @@ +### What is the meaning of this? + +[Troublegun](https://github.com/filipp/Troublegun) is a simple tool for collecting error reports from end users to help +admins with troubleshooting. The idea is to make it as easy as possible for end users +to send helpful troubleshooting info when problems occur. + +### System Requirements + +- Mac OS X (tested with 10.8 and 10.9) +- Python 2.7 or later +- Mail.app or Microsoft Entourage + + +### Configuration + +Navigate to __Troublegun.app > Show package contents > Contents > Resources__ and edit config.ini to your liking. + +Here's an example: + + [message] + name: Our IT guy + address: you@example.com + subject: Problem Report + message: Application: + Problem: + + attachments: screencapture + +Save the file, copy the app to your users' Applications_-folder, add it to their dock. + +### License + +The MIT License (MIT) +Copyright (c) 2016 Filipp Lepalaan + +Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + + +### Thanks + +Icon provided by flaticons.net diff --git a/Troublegun.app/Contents/Info.plist b/Troublegun.app/Contents/Info.plist new file mode 100644 index 0000000..cab3e74 --- /dev/null +++ b/Troublegun.app/Contents/Info.plist @@ -0,0 +1,48 @@ + + + + + CFBundleAllowMixedLocalizations + + CFBundleDevelopmentRegion + English + CFBundleExecutable + applet + CFBundleIconFile + applet + CFBundleIdentifier + com.apple.ScriptEditor.id.Troublegun + CFBundleInfoDictionaryVersion + 6.0 + CFBundleName + Troublegun + CFBundlePackageType + APPL + CFBundleShortVersionString + 1.0 + CFBundleSignature + aplt + LSMinimumSystemVersionByArchitecture + + x86_64 + 10.6 + + LSRequiresCarbon + + WindowState + + dividerCollapsed + + eventLogLevel + -1 + name + ScriptWindowState + positionOfDivider + 333 + savedFrame + 156 168 602 597 0 0 1440 878 + selectedTabView + result + + + diff --git a/Troublegun.app/Contents/MacOS/applet b/Troublegun.app/Contents/MacOS/applet new file mode 100755 index 0000000..4f7d67b Binary files /dev/null and b/Troublegun.app/Contents/MacOS/applet differ diff --git a/Troublegun.app/Contents/PkgInfo b/Troublegun.app/Contents/PkgInfo new file mode 100644 index 0000000..3253614 --- /dev/null +++ b/Troublegun.app/Contents/PkgInfo @@ -0,0 +1 @@ +APPLaplt \ No newline at end of file diff --git a/Troublegun.app/Contents/Resources/Scripts/main.scpt b/Troublegun.app/Contents/Resources/Scripts/main.scpt new file mode 100644 index 0000000..38b8ccd Binary files /dev/null and b/Troublegun.app/Contents/Resources/Scripts/main.scpt differ diff --git a/Troublegun.app/Contents/Resources/applet.icns b/Troublegun.app/Contents/Resources/applet.icns new file mode 100644 index 0000000..0cdd170 Binary files /dev/null and b/Troublegun.app/Contents/Resources/applet.icns differ diff --git a/Troublegun.app/Contents/Resources/applet.rsrc b/Troublegun.app/Contents/Resources/applet.rsrc new file mode 100644 index 0000000..a3d8348 Binary files /dev/null and b/Troublegun.app/Contents/Resources/applet.rsrc differ diff --git a/Troublegun.app/Contents/Resources/config.ini b/Troublegun.app/Contents/Resources/config.ini new file mode 100644 index 0000000..ccc45a5 --- /dev/null +++ b/Troublegun.app/Contents/Resources/config.ini @@ -0,0 +1,7 @@ +[message] +name: Our IT guy +address: you@example.com +subject: Problem Report +message: Application: +Problem: +attachments: screencapture diff --git a/Troublegun.app/Contents/Resources/description.rtfd/TXT.rtf b/Troublegun.app/Contents/Resources/description.rtfd/TXT.rtf new file mode 100644 index 0000000..116a631 --- /dev/null +++ b/Troublegun.app/Contents/Resources/description.rtfd/TXT.rtf @@ -0,0 +1,4 @@ +{\rtf1\ansi\ansicpg1252\cocoartf1265\cocoasubrtf210 +{\fonttbl} +{\colortbl;\red255\green255\blue255;} +} \ No newline at end of file diff --git a/Troublegun.app/Contents/Resources/entourage.scpt b/Troublegun.app/Contents/Resources/entourage.scpt new file mode 100644 index 0000000..b893a61 --- /dev/null +++ b/Troublegun.app/Contents/Resources/entourage.scpt @@ -0,0 +1,6 @@ +tell application "Microsoft Entourage" + set theRecipients to {{address:{display name:"%@", address:"%@"}, recipient type:to recipient}} + set theMessage to make new outgoing message with properties {recipient:theRecipients, subject:"%@", attachment:{file:(POSIX file "%@")}} + open theMessage + activate +end tell diff --git a/Troublegun.app/Contents/Resources/gethelper.sh b/Troublegun.app/Contents/Resources/gethelper.sh new file mode 100644 index 0000000..2071ec7 --- /dev/null +++ b/Troublegun.app/Contents/Resources/gethelper.sh @@ -0,0 +1 @@ +defaults read com.apple.launchservices LSHandlers | grep -B 1 mailto | grep RoleAll | awk 'IFS="=" { print $3; }' diff --git a/Troublegun.app/Contents/Resources/mail.scpt b/Troublegun.app/Contents/Resources/mail.scpt new file mode 100644 index 0000000..ee447a9 --- /dev/null +++ b/Troublegun.app/Contents/Resources/mail.scpt @@ -0,0 +1,10 @@ +tell application "Mail" + set theMessage to make new outgoing message with properties {visible:true, subject:"$subject", content:"$message"} + tell theMessage + make new to recipient at end of to recipients with properties {name:"$name", address:"$address"} + end tell + tell content of theMessage + make new attachment with properties {file name:"$filename"} + end tell + activate +end tell diff --git a/Troublegun.app/Contents/Resources/main.py b/Troublegun.app/Contents/Resources/main.py new file mode 100755 index 0000000..76cbbb0 --- /dev/null +++ b/Troublegun.app/Contents/Resources/main.py @@ -0,0 +1,62 @@ +#! /usr/bin/env python + +import os +import subprocess +import ConfigParser +from string import Template +from tempfile import NamedTemporaryFile + + +def getresource(res): + from os.path import realpath, join, dirname + return join(dirname(realpath(__file__)), res) + +def getconfig(): + config = dict() + ini = ConfigParser.ConfigParser() + inipath = getresource('config.ini') + ini.read(inipath) + for i in ini.options('message'): + config[i] = ini.get('message', i) + + return config + +def gethelper(): + helper = subprocess.check_output(['sh', getresource('gethelper.sh')]) + return helper.strip() + +def screencapture(): + f = NamedTemporaryFile(delete=False, suffix=".png") + f.close() + subprocess.call(['screencapture', '-C', f.name]) + return f.name + +def makemail(config): + helper = gethelper() + + if "com.apple.mail" in helper: + scpt = file(getresource("mail.scpt"), "r") + elif "entourage" in helper: + scpt = file(getresource("entourage.scpt"), "r") + else: + raise Exception("%s is not a supported mail app" % helper) + + compiled_scpt = Template.substitute(Template(scpt.read()), config) + exe = NamedTemporaryFile(delete=False, suffix=".scpt") + exe.write(compiled_scpt) + exe.close() + return exe.name + +def main(): + config = getconfig() + + if 'screencapture' in config.get('attachments'): + config['filename'] = screencapture() + + exe = makemail(config) + subprocess.call(['osascript', exe]) + os.unlink(exe) + + +if __name__ == '__main__': + main() diff --git a/Troublegun.scptd/Contents/Info.plist b/Troublegun.scptd/Contents/Info.plist new file mode 100644 index 0000000..83d5ce5 --- /dev/null +++ b/Troublegun.scptd/Contents/Info.plist @@ -0,0 +1,27 @@ + + + + + CFBundleIdentifier + com.apple.ScriptEditor.id.Troublegun + CFBundleName + Troublegun + CFBundleShortVersionString + 1.0 + WindowState + + dividerCollapsed + + eventLogLevel + -1 + name + ScriptWindowState + positionOfDivider + 333 + savedFrame + 156 168 602 597 0 0 1440 878 + selectedTabView + result + + + diff --git a/Troublegun.scptd/Contents/Resources/Scripts/main.scpt b/Troublegun.scptd/Contents/Resources/Scripts/main.scpt new file mode 100644 index 0000000..b93bd15 Binary files /dev/null and b/Troublegun.scptd/Contents/Resources/Scripts/main.scpt differ diff --git a/Troublegun.scptd/Contents/Resources/config.ini b/Troublegun.scptd/Contents/Resources/config.ini new file mode 100644 index 0000000..f33ab05 --- /dev/null +++ b/Troublegun.scptd/Contents/Resources/config.ini @@ -0,0 +1,8 @@ +[message] +name: Our IT guy +address: you@example.com +subject: Problem Report +message: Application: + Problem: + +attachments: screencapture diff --git a/Troublegun.scptd/Contents/Resources/description.rtfd/TXT.rtf b/Troublegun.scptd/Contents/Resources/description.rtfd/TXT.rtf new file mode 100644 index 0000000..116a631 --- /dev/null +++ b/Troublegun.scptd/Contents/Resources/description.rtfd/TXT.rtf @@ -0,0 +1,4 @@ +{\rtf1\ansi\ansicpg1252\cocoartf1265\cocoasubrtf210 +{\fonttbl} +{\colortbl;\red255\green255\blue255;} +} \ No newline at end of file diff --git a/Troublegun.scptd/Contents/Resources/entourage.scpt b/Troublegun.scptd/Contents/Resources/entourage.scpt new file mode 100644 index 0000000..b893a61 --- /dev/null +++ b/Troublegun.scptd/Contents/Resources/entourage.scpt @@ -0,0 +1,6 @@ +tell application "Microsoft Entourage" + set theRecipients to {{address:{display name:"%@", address:"%@"}, recipient type:to recipient}} + set theMessage to make new outgoing message with properties {recipient:theRecipients, subject:"%@", attachment:{file:(POSIX file "%@")}} + open theMessage + activate +end tell diff --git a/Troublegun.scptd/Contents/Resources/gethelper.sh b/Troublegun.scptd/Contents/Resources/gethelper.sh new file mode 100644 index 0000000..2071ec7 --- /dev/null +++ b/Troublegun.scptd/Contents/Resources/gethelper.sh @@ -0,0 +1 @@ +defaults read com.apple.launchservices LSHandlers | grep -B 1 mailto | grep RoleAll | awk 'IFS="=" { print $3; }' diff --git a/Troublegun.scptd/Contents/Resources/mail.scpt b/Troublegun.scptd/Contents/Resources/mail.scpt new file mode 100644 index 0000000..ee447a9 --- /dev/null +++ b/Troublegun.scptd/Contents/Resources/mail.scpt @@ -0,0 +1,10 @@ +tell application "Mail" + set theMessage to make new outgoing message with properties {visible:true, subject:"$subject", content:"$message"} + tell theMessage + make new to recipient at end of to recipients with properties {name:"$name", address:"$address"} + end tell + tell content of theMessage + make new attachment with properties {file name:"$filename"} + end tell + activate +end tell diff --git a/Troublegun.scptd/Contents/Resources/main.py b/Troublegun.scptd/Contents/Resources/main.py new file mode 100755 index 0000000..76cbbb0 --- /dev/null +++ b/Troublegun.scptd/Contents/Resources/main.py @@ -0,0 +1,62 @@ +#! /usr/bin/env python + +import os +import subprocess +import ConfigParser +from string import Template +from tempfile import NamedTemporaryFile + + +def getresource(res): + from os.path import realpath, join, dirname + return join(dirname(realpath(__file__)), res) + +def getconfig(): + config = dict() + ini = ConfigParser.ConfigParser() + inipath = getresource('config.ini') + ini.read(inipath) + for i in ini.options('message'): + config[i] = ini.get('message', i) + + return config + +def gethelper(): + helper = subprocess.check_output(['sh', getresource('gethelper.sh')]) + return helper.strip() + +def screencapture(): + f = NamedTemporaryFile(delete=False, suffix=".png") + f.close() + subprocess.call(['screencapture', '-C', f.name]) + return f.name + +def makemail(config): + helper = gethelper() + + if "com.apple.mail" in helper: + scpt = file(getresource("mail.scpt"), "r") + elif "entourage" in helper: + scpt = file(getresource("entourage.scpt"), "r") + else: + raise Exception("%s is not a supported mail app" % helper) + + compiled_scpt = Template.substitute(Template(scpt.read()), config) + exe = NamedTemporaryFile(delete=False, suffix=".scpt") + exe.write(compiled_scpt) + exe.close() + return exe.name + +def main(): + config = getconfig() + + if 'screencapture' in config.get('attachments'): + config['filename'] = screencapture() + + exe = makemail(config) + subprocess.call(['osascript', exe]) + os.unlink(exe) + + +if __name__ == '__main__': + main() -- cgit v1.2.3