Ticket #24433: main.3.applescript

File main.3.applescript, 3.5 KB (added by mkae (Marko Käning), 15 years ago)

This version uses 'tell application "X11"' instead of a shell command and uses the correct way to check for existence of kmm's executable.

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        get alias kmymoney
39on error
40        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
41        return
42end try
43
44set command to ""
45
46set kdedirID to ""
47set ICEauthorityID to ""
48set XauthorityID to ""
49
50set kdeDir to (POSIX path of (path to home folder) & ".kde/" as string)
51set ICEauthority to (POSIX path of (path to home folder) & ".ICEauthority" as string)
52set Xauthority to (POSIX path of (path to home folder) & ".Xauthority" as string)
53
54set kdeDirMessage to ""
55
56try
57       
58        POSIX file kdeDir as alias
59        set kdedirID to do shell script "stat -f '%Su' $HOME/.kde"
60       
61end try
62
63try
64       
65        POSIX file ICEauthority as alias
66        set ICEauthorityID to do shell script "stat -f '%Su' $HOME/.ICEauthority"
67       
68end try
69
70try
71       
72        POSIX file Xauthority as alias
73        set XauthorityID to do shell script "stat -f '%Su' $HOME/.Xauthority"
74       
75end try
76
77if ((not kdedirID is equal to "") and not kdedirID = userID) or not ICEauthorityID = userID or not XauthorityID = userID then
78       
79        if (not kdedirID is equal to "") then set kdeDirMessage to (kdeDir & return & " is owned by " & kdedirID & return & return)
80       
81        set fixPermissions to button returned of Â
82                (display dialog (kdeDirMessage Â
83                        & ICEauthority & return & " is owned by " & ICEauthorityID & return & return & Xauthority & return & " is owned by " & XauthorityID & return & return & "They should be owned by " & userID & " for KMyMoney to run properly!") buttons {"Cancel", "Fix"} default button {"Fix"} with icon 2)
84       
85        if fixPermissions = "Fix" then
86               
87                if (not kdedirID is equal to "") then do shell script "chown -R " & userID & " " & kdeDir with administrator privileges
88                do shell script "chown " & userID & " " & ICEauthority with administrator privileges
89                do shell script "chown " & userID & " " & Xauthority with administrator privileges
90               
91        end if
92       
93end if
94
95try
96        tell application "X11"
97                open POSIX path of kmymoney
98        end tell
99on error
100        display alert "There was an error launching KMyMoney." & return & return & "Try 'port installed kmymoney' to verify that port 'kmymoney' is installed." as warning
101end try