Ticket #24618: KMyMoney.applescript

File KMyMoney.applescript, 4.6 KB (added by mkae (Marko Käning), 14 years ago)

Bugfix for starter app in case of non-exisiting files to fix permissions for

Line 
1#---------------------------------------------------------------------------------------------------
2#
3# This program is free software: you can redistribute it and/or modify
4# it under the terms of the GNU General Public License as published by
5# the Free Software Foundation, either version 3 of the License, or
6# (at your option) any later version.
7#
8# This program is distributed in the hope that it will be useful,
9# but WITHOUT ANY WARRANTY; without even the implied warranty of
10# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
11# GNU General Public License for more details.
12#
13# You should have received a copy of the GNU General Public License
14# along with this program.  If not, see <http://www.gnu.org/licenses/>.
15#
16#---------------------------------------------------------------------------------------------------
17#
18# GPL-licensed icons included in applet.icns are courtesy of KMyMoney's developers!
19#
20#---------------------------------------------------------------------------------------------------
21#
22# Authors:
23#  - Brad Giesbrecht <brad@pixilla.com>
24#  - Marko K"aning <MK-MacPorts@techno.ms>
25#
26########################################################
27
28try
29       
30        set userID to do shell script "stat -f '%Su' $HOME"
31       
32end try
33
34set executable to "__PREFIX__/bin/kmymoney" as string
35set kmymoney to (POSIX file executable)
36
37try
38       
39        get alias kmymoney
40       
41on error
42       
43        display alert "There was an error locating KMyMoney's executable." & return & return & "Try 'port installed kmymoney' to verify that port 'kmymoney' is installed." & return & return & "The file we tried to find was:" & return & return & "'" & executable & "'" as warning
44        return
45       
46end try
47
48set command to ""
49
50set kdedirID to ""
51set qtdirID to ""
52set ICEauthorityID to ""
53set XauthorityID to ""
54
55set kdeDir to (POSIX path of (path to home folder) & ".kde/" as string)
56set qtDir to (POSIX path of (path to home folder) & ".qt/" as string)
57set ICEauthority to (POSIX path of (path to home folder) & ".ICEauthority" as string)
58set Xauthority to (POSIX path of (path to home folder) & ".Xauthority" as string)
59
60set kdeDirMessage to ""
61set qtDirMessage to ""
62set ICEauthorityMessage to ""
63set XauthorityMessage to ""
64
65try
66       
67        POSIX file kdeDir as alias
68        set kdedirID to do shell script "stat -f '%Su' $HOME/.kde"
69       
70end try
71
72try
73       
74        POSIX file qtDir as alias
75        set qtdirID to do shell script "stat -f '%Su' $HOME/.qt"
76       
77end try
78
79try
80        POSIX file ICEauthority as alias
81        set ICEauthorityID to do shell script "stat -f '%Su' $HOME/.ICEauthority"
82       
83end try
84
85try
86       
87        POSIX file Xauthority as alias
88        set XauthorityID to do shell script "stat -f '%Su' $HOME/.Xauthority"
89
90end try
91
92if ((not kdedirID is equal to "") and not kdedirID = userID) or ((not qtdirID is equal to "") and not qtdirID = userID) or ((not ICEauthorityID is equal to "") and not ICEauthorityID = userID) or ((not XauthorityID is equal to "") and not XauthorityID = userID) then
93       
94        if (not kdedirID is equal to "") then set kdeDirMessage to (kdeDir & return & " is owned by " & kdedirID & return & return)
95        if (not qtdirID is equal to "") then set qtDirMessage to (qtDir & return & " is owned by " & qtdirID & return & return)
96        if (not ICEauthorityID is equal to "") then set ICEauthorityMessage to (ICEauthority & return & " is owned by " & ICEauthorityID & return & return)
97        if (not XauthorityID is equal to "") then set XauthorityMessage to (Xauthority & return & " is owned by " & XauthorityID & return & return)
98       
99        set fixPermissions to button returned of (display dialog (kdeDirMessage & qtDirMessage & ICEauthorityMessage & XauthorityMessage & "They should be owned by " & userID & " for KMyMoney to run properly!") buttons {"Cancel", "Fix"} default button {"Fix"} with icon 2)
100       
101        if fixPermissions = "Fix" then
102               
103                if (not kdedirID is equal to "") then do shell script "chown -R " & userID & " " & kdeDir with administrator privileges
104                if (not qtdirID is equal to "") then do shell script "chown -R " & userID & " " & qtDir with administrator privileges
105                if (not ICEauthorityID is equal to "") then do shell script "chown " & userID & " " & ICEauthority with administrator privileges
106                if (not XauthorityID is equal to "") then do shell script "chown " & userID & " " & Xauthority with administrator privileges
107               
108        end if
109       
110end if
111
112
113set command to "sh -l -c " & (POSIX path of kmymoney) & " > /dev/null 2>&1"
114
115try
116       
117        do shell script command
118       
119on error
120       
121        display alert "There was an error launching KMyMoney." & return & return & "Try 'port installed kmymoney' to verify that port 'kmymoney' is installed." & return & return & "The command we tried to execute was:" & return & return & "'" & command & "'" as warning
122       
123end try