Edit script syntax - Toggle bluetooth according to power setting

Using a MBPr13 on OSX ML 10.8.4, needing to toggle Bluetooth based on Power source. Found a dated script, but I'm not script savvy so hoping someone could help me edit it:
#! /bin/bash
PREVIOUS_SOURCE=$(pmset -g ps | perl -ne '/(w+) Power/ && print $1');
while [ 1 ]; do
  CURRENT_SOURCE=$(pmset -g ps | perl -ne '/(w+) Power/ && print $1');
  if [ $CURRENT_SOURCE != $PREVIOUS_SOURCE ]; then
    PREVIOUS_SOURCE=$CURRENT_SOURCE
    if [ $CURRENT_SOURCE = "AC" ]; then
      blueutil on
    else
      blueutil off
    fi
  fi
  sleep 5
done
When I compile in Apple Script Editor, I get "Expected expression but found unknown token" Syntax Error and the $ character is highlighted (as above).
Comments posted on the web page where I found this suggest that some of the "escapes on the word characters" have been stripped? Can anyone suggest how this could be edited to work?
Cheers, Sla

The previous script doesn't quite work properly, this one is better:
tell application "System Preferences"
  activate
          set the current pane to pane id "com.apple.preferences.bluetooth"
end tell
set _power to do shell script "pmset -g | grep AC"
set _power to last character of _power
if _power = "*" then
          tell application "System Events"
                         set _status to checkbox "On" of window "Bluetooth" of application process "System Preferences"
                         tell _status
                                        if not (its value as boolean) then click _status
                         end tell
          end tell
else
          tell application "System Events"
                         set _status to checkbox "On" of window "Bluetooth" of application process "System Preferences"
                         tell _status
                                        if (its value as boolean) then click _status
                         end tell
          end tell
end if
tell application "System Preferences" to quit

Similar Messages

  • Can't edit script

    Hi,
    I've looked through forums where others have experienced the same problem:
    - text is not editable, and seems to be locked.
    Have tried Ctrl key to try and toggle this off, but only worked once.
    What is the solution to having full access to an editable script please?

    Hi Rohit,
    I can send you the file in a few months after we've concluded filming.
    For now I can't share the file.
    Is this a common issue people have? I discovered a few similar cases in forums online.
    Thanks,
    stefan

  • Reflection errors in Field Data Edit Scripting context(Line Item class)

    Hello Experts,
    I have a script that does some validation in the Field Data Edit Scripting context of the "Line Item" class, and I  have "MATERIAL" as my target. when i try throwing an Application Exception in this context I get a reflection error message box instead of the message I have passed to the Application Exception constructor.
    your help will be greatly appreciated.
    kind regards,

    One thing to be aware of is that no matter how you choose to construct your exception in field, field data edit and collection scripts, the attribute is always set to the be the taget field/collection. Have you noticed that? The script designers made things that way. What's going on here is that the exception raised in the Interprer is caught by the Script Manager and rethrown with the script target as the attribute and your raised exception as the exception.
    One other thing I would point out is that scripts set to execute on the Collection Member Lifecycle event tend to be poor performers.  You can get a faster result if you edit whole collection and chain the errors onto one ChainException. I can only speculate as to why, but I have seen major improvements in complex scripts if I iterate the whole collection, versus implementing a collection memeber lifecycle validate event. This is counter-intuitive, but there it is.
    Finally, exceptions raised in Collection Lifecycle Events that interupt the overall save process in the prescence of parent document Lifecycle Validation events can result in partially saved data. I observed this issue a few years back and it may be resolved now. The only member lifecycle event I use is Created, to lock, default, etc.
    So, for your particular problem, you may want to rethink your strategy and see if you can get things to work for you bypassing that reflection issue. If you still can't raise the exception on MATERIAL, maybe you can raise it on another field, because another advantage of this approach is that you have full control to raise any error on any field on the Line Items.

  • Bluetooth mouse losing power every few seconds.

    bluetooth mouse losing power every few seconds. What is the problem and how do I fix it?

    Hello:
    It is probably failing.
    Take it to an Apple store for diagnosis.
    Barry

  • Editing Script Component in VS2013 launches VS2012?

    New SSIS developer here.
    Using VS Premium 2013 RTM (12.0.21005.1 REL) with SSDT 12.0.30919.1 and SQL Server Integration Services.
    I have a Business Intelligence -> Integration Services project (an SSIS project), and when I create a Script Component in a Data Flow Task and click "Edit Script...", it launches Visual Studio 2012.
    The ScriptLanguage property for the Script Component is set to "Microsoft Visual C# 2012". I don't see an option for "Microsoft Visual C# 2013" (if such a thing exists?).
    Questions:
    1. How can I set VS2013 to call VS2013 (and NOT VS2012) for editing the C# in my Script Component? I can create/edit/build a straight C# project just fine in VS2013, so how to do I get VS2013 to edit C# in the Script Component instead of launching VS2012?
    2. What is the relationship between the version of Visual Studio ("Visual Studio 2013") and the version of the languages available/defaulted in the ScriptLanguage setting ("Microsoft Visual C#/Visual Basic 2012")?
    Thank you very much for your help.

    Answer:
    You cannot as the Script Task is done via VSTA which is VS 2012 Shell. And there is not such need;
    Arthur
    MyBlog
    Twitter

  • AW memory error when clicking "Edit Script" on ICM 7.2.7 Script editor

    I have installed a new AW/HDS(ICM 7.2.7).Installation went on smoothly but when i open a exist script through script editor and click "Edit Script", I get memory error "The instruction at "0x7c1..the memory could not be read" and the script editor closes automatically. I am able to make changes in Configuration Manager without any issues.The new server is configured as a secondary pointing to a primary distributor in a different region.Let me know if anyone has faced this issue or have any idea.All the ICM processes on the server looks fine. I am able to open the same script from other AWs without any issues.
    Thanks
    KMS

    I would run "Initialize Local Database" on the secondary to drop the local AW DB and rebuild it from the Central Controller.
    Then I would try stopping the primary Distributor so the Secondary establishes the real-time feed to the Router by itself and check.
    Regards,
    Geoff

  • Wifi toggle & Bluetooth toggle app

    Hi,
    I love my iPhone but after coming from windows powered phones etc I really miss the option to easily toggle the wifi and Bluetooth on and off.
    I use Bluetooth for my car kit but really hate having so many menus to navigate trough to turn bluetooth on, as I always keep it off to preserve battery life.
    Same with wifi I use it a lot but at times of the day it's not needed and would love a simple app on my home screen just to toggle them on and off quickly.
    When will one be available???
    Regards
    Scott

    Hi, Scott:
    I'm wishing there was an app like you described, too. After having many excessive battery drain problems, I'd like to be able to simply toggle Bluetooth "On" or "Off" from a Home screen. Wi-Fi would be good too. In searching today for such an app, one doesn't exist except for jailbroken phones, and I don't want to deal with the incessant tweaks required for that.
    You know that you and I aren't the only ones who have thought of this. I see Web posts going back at least two years about it. Coupled with the many user problems I see posted about battery drains on Bluetooth and Wi-Fi, I'd say the reason Apple hasn't released an app for this boils down to money. Apple would makes more money by draining batteries and charging to replace them than by doing a sensible toggle app.
    As a company, Apple seems to forget that we're paying them for a top-of-the-line product, rather than them trying to make us feel like they're doing us a favor accepting our money.

  • Upgraded to VS 2013 - cannot edit script in SSIS script component

    I'm running SQL Server 2014 and just recently upgraded to Visual Studio 2013 from 2012. I was attempting to develop an SSIS solution today - the first time since the upgrade - and was blocked because I wasn't able to edit the script for a script component
    in an SSIS package.
    I can add the object to a data flow but clicking on the "Edit Script..." button yields no response whatsoever. No error, no scripting environment. 
    I'm running VS2013 Ultimate with SSDT 2013, and SS 2014 Enterprise. 
    My hunch is that there are components missing somewhere but I don't know enough about this platform to piece together how things are related. I have nearly every option installed for VS2013 except for Windows Phone and app store development.
    I didn't have an issue previously and I'm unsure how to debug this - especially since I'm not a real SDE. 
    Thanks in advance for your help

    Hi Torben E,
    Maybe that you were unaware that you post this issue in Visual Studio Setup and Installation forum. This forum is to discuss and ask questions about the install and setup of Visual Studio. Obviously, this case is out of the scope of this forum.
    I'm unsure which forum is better for this case. Is Visual Studio General forum? Or SQL Server Integration Services forum? But I'd like to find a suitable forum along with you.
    >>I was attempting to develop an SSIS solution today - the first time since the upgrade - and was blocked because I wasn't able to edit the script for a script component in an SSIS package.  
    I see that you upgrade to Visual Studio 2013 from 2012. And you didn't have an issue previously. Do you mean that you can create SSIS project and edit the script for a script component before you upgrade VS?
    >>ERROR: Cannot resolve reference coloader80.dll,processorArchitecture="X86",type="win32",version="1.0.0.0".
    From the error message, it seems that the IDE can't find the coloader80.dll. Can you find this dll in your PC? Does it exist in the path ""C:\Program
    Files (x86)\Microsoft
    Visual Studio 11.0\Common7\IDE\"?
    If you can find it, please try to register the oleaut32.dll as the thread below mentioned to see if this method can solve this issue.
    https://social.msdn.microsoft.com/Forums/en-US/68d89658-b35f-4828-a9b1-31cf5cfc7717/coloader80dll-and-critical-debug-error?forum=Vsexpressvb
    This error is caused by the registration for oleaut32.dll was corrupted, there maybe other dll that also named oleaut32.dll, so visual studio could not
    find the right oleaut32.dll.
    So please download the OleAutClean.msi in this link and run it, to clean all the registration of oleaut32.dll.
    http://download.microsoft.com/download/a/9/3/a93f06e7-5828-460c-a78b-ab89c77b6957/OleAutClean.msi
    Then register the oleaut32.dll again.
    1.     
    Right click the Commandline to run the commandline as administrator.
    2.     
    In the commandline, run the following command if you are using Win7 or vista.
    regsvr32 "%CommonProgramFiles%\microsoft shared\VS7DEBUG\coloader80.dll" . Then you will see a dialog that shows the registration
    successes.
    Best regards,
    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click
    HERE to participate the survey.

  • Script Editor takes forever to load with SSIS 2012 packages in VS 2012 when you click on Edit Script... button

    Hi,
    I'm upgrading some SSIS Packages to the SQL 2012 Project deployment model. However, when I click on the Edit Script... button in a Script Editor Task, Visual Studio just sits there for minutes until it sometimes opens, sometimes doesn't. Surely this should
    open up pretty much instantaneously. Can anyone shed any light on why this is happening ?
    Thanks
    Dave Evans

    Hi Dave Evans,
    It might be due to permission issue, please try to uncheck "Check for publisher’s certificate revocation" under the "Security" group in "Advanced" tab in "Internet Options", please see:
    http://stackoverflow.com/questions/13540151/ssis-script-editor-loads-very-slow 
    Thanks,
    Eileen
    Eileen Zhao
    TechNet Community Support

  • How can i edit script component in another machine?

    Hello everyone,
    i am using sqlserver data tools to build a package..
    i have alot of script components...the problem is i wrote this package in machine A ... when i take the whole solution in machine B 
    i can not edit or see the script components projects files etc...
    am i missing an atribute at package solution/project file?
    because in ssis 2008 r2 version i can edit all of components (script componet,oledb source component...etc.)
    ...but  in 2012 version of ssis i can not edit script component project..
    thanks a lot..
    evgeni

    Evgeni
    because in ssis 2008 r2 version i can edit all of components (script componet,oledb source component...etc.)
    ...but  in 2012 version of ssis i can not edit script component project"
    I guess you need to upgrade the package/solution 1st to the SSIS 2012 format.
    You need to go to Start-Microsoft SQL Server 2012->Integration Services and choose
    Project Conversion Wizard .
    Once the project (not just a package) is converted to SSIS 2012 open it in SSDT, access your Script Component and then choose
    Design Script button
    Arthur My Blog

  • Calculate retention according to a set percentage

    hi,
    What mean of retention?
    What the obverse in oracle handle the same functionality
    and i can Calculate retention according to a set percentage or a fixed amount while recording an invoice
    thanks

    Hi Umapathy,
    Yield and Scrap are user entry fields where you can have restriction on entered qty by changing  under delivery and over delivery to error through OPK4 config as shown below. Agree that any qty can be entered in any field (Yield or Scrap)
    OR
    You can define the operation scrap. Read the below doc for more details.
    http://scn.sap.com/docs/DOC-52834
    OR
    Another option is to use exit and write your logic based on input yield and loss.
    Thanks & Regards,
    Ramagiri

  • GS70 laptop power setting issue (it does not save my setting even with admin)

    laptop is decent, but the power setting does not save when i (1) shutdown (2) go through fn + F5;power modes on msi gs70
     I want to change simple power options such as:
    -do nothing when close lid
    -other etc in power options
    will revert back to original out of box setting when i shutdown....
    Its not cool that I have to change 5 power option setting so that I can leave my laptop to download while I am out of house. 
    what i've tried:
    I changed regedit for power setting option to give me admin/allow save/apply on power settings (this is windows 8)
    Tried w/o messing with regedit but didnt work before messing with regedit on admin/saves
    some help would be great! Been 6 mths with this power option issue :/ already at the point to chuck it out of my 20th floor window

    I had the same problem do this
    http://www.raymond.cc/blog/archives/2011/03/23/enable-save-tabs-on-exit-for-firefox-4/
    I do what this guy said and it is allright again

  • Is it possible to catch a PowerShell script output when an exit code is setted?

    Hi,
    i'm using TEO 2.1.2 with the hotfixes from 1 to 12 already installed and i have a problem using the "Execute Windows PowerShell Script" in reading the output of a PowerShell script if an exit code is expressly setted . For example if i try to execute a script like:
    the output given by the activity is only 0 (like the exit code).
    This is a problem if i use a script with multiple exit codes corrisponding to different kind of situations and different outputs like the following:
    if($flag -eq "0")
       Write-output "Hello"
       exit 0
    elseif ($flag -eq "1")
       Write-output "Error 1"
       exit 1
    else
      Write-output "Error 2"
      exit 2
    or if i call an executable which exit codes i want to identify by a readable description.
    Anyone knows a way to solve this issue?
    Thanks a lot,
    bye.
    Giulio

    Thanks Shaun,
    i was already looking toward this kind of approch, but i was also curious if there was a different way of doing this.
    Anyway just a little annotation about your line of code, in Tidal 2.1.2 at least, Write-host doesn't work right, echo or Write-Output are fine but Write-host seems to be ignored. To the following script:
    the output is
    Maybe i'm missing something. Regarding an upgrade, as a devoloper i'd really like to try the improvement of the new version but this is not a decision I can make.
    Thank you,
    bye.
    Giulio

  • Can anyone confirm if you can in fact shoot/edit (perhaps using a less than best video setting) on a Canon XA20 or Sony HXR-NX30U with iMovie 10 (Mavericks)? I do not want to convert files. Thx.

    Can anyone confirm if you can in fact shoot/edit (perhaps using a less than best video setting) on a Canon XA20 or Sony HXR-NX30U with iMovie 10 (Mavericks)? I do not want to convert files. Thx.

    Hi road.north,
    Welcome to the Support Communities!
    The article below will help you determine which cameras are supported for iMovie '10
    Apple - iLife Help - iMovie Supported Cameras
    http://help.apple.com/imovie/10/cameras/en/index.html?lang=en_US
    Cheers,
    - Judy

  • After I edited my contact list on my iphone I set up the icloud account.  Now all of my old contacts have been added to the edited ones.  If I delete the icould will I lose all of my contacts or just the ones brought in by icloud?

    After I edited my contact list on my iphone I set up the icloud account.  Now all of my old contacts have been added to the edited ones.  If I delete the icould will I lose all of my contacts or just the ones brought in by icloud?

    You cannot delete an Apple ID, you can just stop using it. If your photos are still on your phone now, then I suggest you do back them up. Transfer them from the phone into your iPhoto Library. iCloud only backs up your Camera Roll automatically. But the Camera Roll only contains new photos that were taken but not yet transferred using iTunes.

Maybe you are looking for