Apple Event: May 7th at 7 am PT

Looks like no one’s replied in a while. To start the conversation again, simply ask a new question.

Application Issues!?!

So I made the following application to make my girlfriends life easire with streaming movies since shes fairly illiterate with computers. Bulit it, Tested it, and it worked on my laptop, but when it is on hers, the server update, caffeine, and brightness won't work at all. Any one have any idea what could be going on? I have 10.8.2 she has 10.7.x


Here is the AppDelegate.applescript:


--

-- AppDelegate.applescript

-- Plex Simple Server

--

-- Created by Riley Lloyd on 2/2/13.

-- Copyright (c) 2013 Riley Lloyd. All rights reserved.

--


script AppDelegate

propertyparent : class"NSObject"

property mainWindow : missing value -- outlet connected to the main window

property thePID : missing value

on applicationWillFinishLaunching_(aNotification)


-- Insert code here to initialize your application before any files are opened

set myBundle to current application's NSBundle's mainBundle()

set backgroundImage to current application's NSImage's alloc's initWithContentsOfFile_(myBundle's pathForResource_ofType_("BG", "jpg"))

backgroundImage's setSize_({480, 360}) -- match window size

mainWindow's setBackgroundColor_(current application's NSColor's colorWithPatternImage_(backgroundImage))

end applicationWillFinishLaunching_

on startServer_(applescript)

set PowerSource to (do shell script "pmset -g ps")

do shell script "sudo ifconfig en1 up" with administrator privileges

repeat until PowerSource does not contain "Battery Power"

set PowerSource to (do shell script "pmset -g ps")

if PowerSource does not contain "AC Power" then

display alert "Please plug your computer in to a power source, then click continue." buttons {"Cancel", "Continue"}

set theAnswer to button returned of the result

if theAnswer is "Continue" then

set PowerSource to (do shell script "pmset -g ps")

if PowerSource does not contain "Battery Power" then

exit repeat

else

delay 1

end if

end if

if theAnswer is "Cancel" then

return

end if

end if

end repeat

ifapplication"Plex Media Server"isnot running then

tellapplication"Plex Media Server"toactivate

end if

end startServer_

on stopServer_(applescript)

tellapplication"System Events"

set isOpen to exists process "Plex Media Server"

end tell

if isOpen then

tellapplication"Plex Media Server"toquit

else

display alert "Server was not running to begin with."

end if

end stopServer_

on updateServerLibrary_(applescript)

tellapplication"System Events"

set is_running to exists process "Plex Media Server"

end tell

if is_running then

do shell script"'/Applications/Plex Media Server.app/Contents/MacOS/Plex Media Scanner' -s -r"

return

else

display alert "Please start the server first."

end if

end updateServerLibrary_

on disableSleep_(sender)

set thePID to (do shell script"caffeinate &> /dev/null & echo $!")

end disableSleep_

on enableSleep_(sender)

if thePID is missing value then return -- no process

do shell script "kill $(pgrep caffeinate) " & thePID

set thePID to missing value -- reset for next time

end enableSleep_

on brightnessUp_(applescript)

set theVariable to 0

repeat until theVariable = 16

tellapplication"System Events"

key code 113

end tell

set theVariable to theVariable + 1

end repeat

end brightnessUp_

on brightnessMed_(applescript)

set theVariable to 0

repeat until theVariable = 16

tellapplication"System Events"

key code 107

end tell

set theVariable to theVariable + 1

end repeat

set nextVariable to 0

repeat until nextVariable = 9

tellapplication"System Events"

key code 113

end tell

set nextVariable to nextVariable + 1

end repeat

end brightnessMed_

on brightnessDown_(applescript)

set theVariable to 0

repeat until theVariable = 16

tellapplication"System Events"

key code 107

end tell

set theVariable to theVariable + 1

end repeat

tellapplication"System Events"

key code 113

end tell

end brightnessDown_

on applicationShouldTerminateAfterLastWindowClosed_(sender)

returntrue

end applicationShouldTerminateAfterLastWindowClosed_

on applicationShouldTerminate_(sender)

if thePID is missing value then return -- no process

do shell script "kill $(pgrep caffeinate) " & thePID

set thePID to missing value

return current application's NSTerminateNow

end applicationShouldTerminate_

endscript

MacBook Pro, OS X Mountain Lion (10.8.2), 2.3 GHz i5, 4GB RAM, OCZ 120GB SSD

Posted on Feb 8, 2013 1:47 PM

Reply
11 replies

Feb 11, 2013 7:31 PM in response to MacMan240

In the various shells you can set a directory lookup order in the $PATH environment variable that is used when trying to find utilities that you have not provided a full path for. The do shell script command uses a default shell which should have paths to the standard locations, but when distributing applications to other machines you should get into the habit of using a full path and not assume that $PATH is set correctly or is the same as on your machine (especially when using third party utilities that can be installed anywhere). For example, the pmset and caffeinate utilities are in /usr/bin/ (e.g. /usr/bin/caffeinate), while kill is in /bin (e.g. /bin/kill).


I don't think that the paths are the problem, but pmset needs to be run as root in order to modify any settings, so perhaps there are permissions issues with the others - is your girlfriend running from an admin account?

Feb 11, 2013 8:08 PM in response to red_menace

I'm also not sure it's even admin rights. For instance the following section of code doesn't even work to lower brightness to lowest lit setting:



on brightnessDown_(applescript)

set theVariable to 0

repeat until theVariable = 16

tell application "System Events"

key code 107

end tell

set theVariable to theVariable + 1

end repeat

tell application "System Events"

key code 113

end tell

end brightnessDown_

Application Issues!?!

Welcome to Apple Support Community
A forum where Apple customers help each other with their products. Get started with your Apple ID.