Skip to content

Instantly share code, notes, and snippets.

@joshua-d-miller
Created July 22, 2021 18:23
Show Gist options
  • Save joshua-d-miller/1090cd38cf10a91e8ca486a0bc52dd2f to your computer and use it in GitHub Desktop.
Save joshua-d-miller/1090cd38cf10a91e8ca486a0bc52dd2f to your computer and use it in GitHub Desktop.
TeamViewer 15 PreInstall Script
#!/usr/local/bin/psupython
# pylint:disable=C0103, W0703, E0611, W0107
'''TeamViewer 15 PreInstall Script'''
# This will configure our initial settings for
# TeamViewer version 15 and prepare for install
# Joshua D. Miller - josh@psu.edu
# August 13, 2020 - The Pennsylvania State University
from os import listdir, path, remove
from shutil import rmtree
from Foundation import (CFPreferencesSetValue,
CFPreferencesSynchronize,
kCFPreferencesAnyUser,
kCFPreferencesCurrentHost)
def main():
'''Main function that will lay down a configuration
using pyObjC's CFPreferencesSetValue and CFPreferencesAppSynchronize
so that these settings will be applied when TeamViewer first runs'''
teamviewer_bundle = 'com.teamviewer.teamviewer.preferences'
tv_prefs = {}
# Set the password Binary decoded from Hex
# Obtain this by setting the password manually on
# TeamViewer 8 and using /usr/bin/defaults read
# on PermanentPassword. You will of course need
# to remove all the spaces and the brackets
# Set the Options Password Binary decoded from Hex
# Use same method as above to obatain but look for
# OptionsPasswordAES
tv_prefs['OptionsPasswordAES'] = (
'').decode('hex')
# tv_prefs['OptionsPasswordAES'] = ('optionbinaryhere').decode('hex')
# Remove initial Dialog
tv_prefs['HostInfoDialog'] = 0
# Full Access even when logged out
tv_prefs['ACFullAccessOnLoginScreen'] = 1
# Always Send Crash Reports so users don't see this dialog
tv_prefs['SendAlwaysCrashLogReport'] = 1
# Old TeamViewer configs to look for
old_config_names = ['com.TeamViewer8.Settings',
'com.teamviewer.teamviewer9',
'com.teamviewer.teamviewer10',
'com.teamviewer.teamivewer.preferences']
# Remove old TeamViewer Config Files
# from /Library/Preferences should they exist
for item in old_config_names:
for filename in listdir('/Library/Preferences/'):
if item in filename:
try:
old_config = path.join(
'/Library/Preferences/', filename)
remove(old_config)
except Exception:
continue
# Remove TeamViewer 8 Application folder if it
# was left behind
try:
rmtree('/Applications/TeamViewer 8/')
except Exception:
pass
try:
remove('{0:}{1:}{2:}'.format(
'/Library/Preferences/', teamviewer_bundle, '.plist'))
except StandardError:
pass
try:
for key, value in tv_prefs.items():
if 'AES' in key:
CFPreferencesSetValue(
key, buffer(value), teamviewer_bundle,
kCFPreferencesAnyUser, kCFPreferencesCurrentHost)
else:
CFPreferencesSetValue(
key, value, teamviewer_bundle,
kCFPreferencesAnyUser, kCFPreferencesCurrentHost)
CFPreferencesSynchronize('com.teamviewer.teamviewer.preferences',
kCFPreferencesAnyUser, kCFPreferencesCurrentHost)
except Exception as error:
print error
exit(1)
if __name__ == '__main__':
main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment