Changing background via apple script

Hello,
I manage a small deployment of different macintosh products and I currently have to run 5 different images so that the background images look right on all the various resolutions. I have been working on a piece of applescript to prompt the user on first startup to select their hardware type to apply the proper background image but I am running into a few issues.
Firstly the method I am using limits me to three options and I cant seem to find any documentation on how the list function works.
Second, I keep getting errors saying the files can't be found.
Here is the code (with personal details removed) that I am working with
display dialog "Choose your hardware type" buttons {"17MBP", "15MBP", "iMac21"}
set situation to the button returned of the result
tell application "Finder"
          set desktop picture to {"MacOSX:Users:USERNAME:Technical:Backgroundimages:" & situation & ".gif"} as alias
end tell
I would really like it to automatically detect the hardware type but I don't think that is possible. The error I currently get says:
error "File MacOSX:Users:USERNAME:Technical:Backgroundimages:15MBP.gif wasn’t found." number -43 from "MacOSX:Users:eventequipment:Technical:Backgroundimages:15MBP.gif"

Applescript panels are limited to three buttons.  if you need more than three choices, use the choose from list command:
choose from list {"alpha", "beta", "gamma", "delta", "epsilon"}
however, you ought to be able to gather the information you need without user interaction.  you can base a choice on machine type using code like the following:
set machineType to paragraph 6 of (do shell script "system_profiler SPHardwareDataType")
if machineType ends with "MacbookPro2,2" or machineType ends with "…" then
          set situation to "MBP15"
else if machineType ends with "…" or machineType ends with "…" then
          set situation to "MBP17"
else if machineType ends with "…" or machineType ends with "…" then
          set situation to "iMac21"
else
  -- set default or throw error
end if
or it might be more convenient to base it on screen resolution using something like the following
set displaySize to paragraph 17 of (do shell script "system_profiler SPDisplaysDataType")
if displaySize ends with "1440 x 900" then
          set situation to "MBP15"
else if displaySize ends with "…" or displaySize ends with "…" then
          set situation to "MBP17"
else if displaySize ends with "…" or displaySize ends with "…" then
          set situation to "iMac21"
else
  -- set default or throw error
end if

Similar Messages

  • Automatic graphic switch via Apple Script

    hi community,
    I would like to change the "Automatic graphics switching" (tick on / tick off) via an Apple Script. I made the following script and it works, except with line "click chckbox 2". Here it ticks the box "Show battery status in menu bar". With "click checkbox 1" it takes the "Lock-Button".
    I would be glad if anybode could tell me the right code for ticking the checkbox "automatic graphics switching" via Apple Script.
    Thanks a lot
    PS: Yes I know that tool gfx Status, but I wanna do this via Apple Script.
    tell application "System Preferences"
      activate
              set current pane to pane "com.apple.preference.energysaver"
              delay 0.5
              tell application "System Events"
                        tell process "Systemeinstellungen"
                                  tell window "Energie sparen"
      click checkbox 2
                                            delay 0.5
                                  end tell
                        end tell
              end tell
      quit
    end tell
    quit

    Hello
    You may try this. It works with MacBook Pro 2010 under 10.6.5.
    tell application "System Preferences"
        set current pane to pane id "com.apple.preference.energysaver"
    end tell
    tell application "System Events"
        tell process "System Preferences"
            tell window 1
                tell group 1 -- automatic graphics switching
                    tell checkbox 1 -- automatic graphics switching
                        click
                    end tell
                end tell
            end tell
        end tell
    end tell
    And the script below will set the option to the specified value.
    set_automatic_graphics_switching(0)
    on set_automatic_graphics_switching(i)
            integer i : status of automatic graphics switching
                0 : off (unchecked)
                1 : on    (checked)
        if i is not in {0, 1} then error "Invalid argument: " & i number 8000
        tell application "System Preferences"
            set _was_running to running
            set current pane to pane id "com.apple.preference.energysaver"
        end tell
        tell application "System Events"
            tell process "System Preferences"
                tell window 1
                    tell group 1 -- automatic graphics switching
                        tell checkbox 1 -- automatic graphics switching
                            if value ≠ i then click
                        end tell
                    end tell
                end tell
            end tell
        end tell
        if not _was_running then
            tell application "System Preferences" to quit
        end if
    end set_automatic_graphics_switching
    Hope this may help,
    H

  • Starting applications from a keynote via Apple Script?

    Is there any way to start an application from a keynote via Apple Script?

    Welcome to the forums!
    Keynote does not support the use of AppleScript in that fashion.

  • Is it possible to set a files label on opening via apple script?

    Hi,
    I would like to mark files which have been opened with i.e. a red lable.
    Would that be possible using apple script?
    If yes how would that script look like?
    Thanks in advance.

    I don;t know of anyway of doing this in Applescript. There is the ability to monitor files using launchd, WatchPaths,  but you need to know the files your monitoring before hand so it won't work for this.
    Again if the domain is limited, that is it's only a certain application or a certain folder you're interested in it might be possible to put something together in Applescript but as a general use, system wide, solution I don;t think it can be done.
    One other possibility would be to use the Finder and smart folders. You could look for all files in a certain folder or system wide that have been acessed in the past period and then mark those. Something along those lines is doable with eiter the Finder or a script.
    regards

  • Open & close iTunes every night via Apple Script

    What I would like to do is have my Mac come out of sleep at 3am, open iTunes and download all my podcasts and then go back to sleep. Is this possible with Apple Script?

    In System Preferences>Energy Saver click on 'Schedule' and set 'Start Up or Wake' to 3 AM
    In iCal set up an event for 3.05, setting an alarm to Open File and selecting iTunes.
    Suppose you want to allow half an hour:
    In AppleScript Editor, write
    tell application iTunes to quit
    tell application "Finder" to sleep
    and save it somewhere as a script, not an application.
    Set up an event in iCal for 3.35 with an alarm, setting it to Run Script and selecting your script.

  • Hiding Folders via Apple Script

    Good evening,
    When i installed Leopard a got up a little Issue: When i look in my harddrive i can see the the folder "var,usr,etc" ... in the normal Finder Window.
    Well i thought it would be some kind of a bug so i helped myself and used a little apple script i allreade used in Tiger to hide all these annoying folders like "Microsoft Users Data etc." You know what i mean
    My Script does this:
    +set myfile to choose file+
    +tell application "System Events" to set visible of myfile to false+
    +tell application "Finder" to update myfile+
    I should be able to pick a file (have done the same for folders, too) and hide it from the normal Finder window. Well it works fine on causaul folder and data.
    But on these UNIX Folder i mentoined it wont work. My Question: How can i get this to work? (I thought of missing admin priviledges?)

    Try the instructions in this article.
    (25833)

  • Change password with apple script

    HI there,
    i'm using the do shell script "dscl . -passwd /Users/my username 1"
    it runs without problems but its not changing the password.
    please advise,
    Rafi.

    You are using "-test" instead of "-passwd" for starters
    then you have a space in the username:
    do shell script "dscl . -test /Users/ rafi test 123"
    should be
    do shell script "dscl . -password /Users/rafi test 123"
    I am not an expert in dscl, but the best way for you to test whether do shell script is going to work is to run it in Terminal first.

  • Retrieve duration of sound files via Apple Script - System Events

    I need to get more details of my sound files into a FileMaker 10 Database as it is possible by using the FileMaker import function. There ist a complicated way by going first through iTunes and than to FileMaker. Now I found out, that part of the information displayed when pushing cmd+i can be retrieved with this:
    tell application "System Events"
    properties of file "/Volumes/MacHD/singsong.mp3"
    end tell.
    But duration, channels, bitrate are not accessible. Is this a general problem with metadata? May be if I got a hint how to retrieve meta-data from .jpg files I might be able to apply this also on .mp3

    Try the AppleScript forum under OS X Technologies.

  • Apple Script to watch any network connectivity to my mac

    Hi All,
    I am looking for a apple script, when that runs it tell or display a dialog box with connection number(s) or the connected machine info or IP address or when any other machine connect to my mac then display a dialog box that someone is connected.
    is this is possible via apple script??

    You need "Little Snitch"
    I believe there's a trial version available...  It's good for like 30 days.
    A script to do what you're looking for would be really really complicated.
    http://www.obdev.at/products/littlesnitch/download.html

  • Apple Script command on background image

    Hello,
    So the thing is.
    I want to creat this apple script that would react only when i switch to a certain space.
    I searched in the interent and found out that the Mac has no easy way of finding out, on which space it is on, so my questions is.
    Would it know what background image is on that space, so that if I changed to a certain space, it would recognise the background image file, and run my script.
    I have just thought of this my self, so I will be testing too.
    But I wanted to know if anyone one els out there has thought of it first and found an answer.
    Thank you

    Please consider submitting an enhancement request to Apple, requesting that information on the spaces be made available to applications and scripts.

  • How do I get my messages to come through on my ipad Via my mobile number? They always used to but I've had to change all my Apple ID if that has anything to do with it? In iMessages it will only take an email address!

    How do I get my messages to come through on my ipad Via my mobile number? They always used to but I've had to change all my Apple ID if that has anything to do with it? In iMessages it will only take an email address!

    Hi EmilyWick123!
    Here is an article that will help you address this question about linking your Apple ID and phone number:
    iOS and OS X: Link your phone number and Apple ID for use with FaceTime and iMessage
    http://support.apple.com/kb/ht5538
    Thanks for being a part of the Apple Support Communities!
    Regards,
    Braden

  • Please help!! Using Apple Script in Automator for Quicktime

    I would like to add some metadata to a batch of quicktime movies and then make the files unable to be altered and re-saved so that I can post them on the web. If I open a movie in quicktime and run the following apple script I can then perform save as of movie A into movie B and movie B cannot be altered.
    tell application "QuickTime Player"
    set saveable of movie 1 to false
    -- save self contained
    end tell
    I would love to be able to do this on a batch level in automator however I cannot figure out how to pass automator items to the apple script so that their saveable can be set to false, and after this I cannot figure out how to have to movies re-saved so the changes will take effect.
    Any help at all would be greatly appreciated.

    how are you passing files to apple script? as finder items?
    the following should work then
    <pre style="
    font-family: Monaco, 'Courier New', Courier, monospace;
    font-size: 10px;
    margin: 0px;
    padding: 5px;
    border: 1px solid #000000;
    width: 720px;
    color: #000000;
    background-color: #ADD8E6;
    overflow: auto;"
    title="this text can be pasted into the Script Editor">
    on run {input, parameters}
    tell application "Finder"
    repeat with cur_file in input
    set fname to (name of (get info for cur_file) as text)
    tell application "QuickTime Player"
    open file (cur_file as text)
    set saveable of document 1 to false
    tell application "Finder" to set new_item to (path to desktop as string) & fname
    save self contained document 1 in new_item
    delay 1
    close document 1
    end tell
    end repeat
    end tell
    end run
    </pre>
    the above will dump the modified files onto your desktop and give them the same names they had before. You can adjust that as you like of course.

  • Apple Script/Program start through link on HTML page

    Dear Apple Gurus
    Probably I'm asking something silly, but I don't know any other way to solve my problem.
    I have to do some training videos about the finder and system tools. To have it easy, I would like to ad some buttons to the project where you can start an apple script which does execute some commands just explained in the video. Untill know I'm intend to do the hole thing inside QT but maybe a HTML page does the job too.
    My problem is now, how can I start a AppleScript out of a Movie or HTML page.
    Is this possible at all or are there any other solutions to to the job?
    Best regards
    Thomas Thaler

    Hi Thomas,
    Yes, you play movies in a smil presentation.
    You can define as many regions as you want. You difine regions in the layout:
    <layout>
    <root-layout background-color="blue" width="320" height="290"/>
    <region id="videoregion" top="0" left="0" width="320" height="240" fit="meet"/>
    <region id="textregion" top="240" left="0" width="320" height="30"/>
    <region id="linkregion" top="270" left="0" width="320" height="20"/>
    </layout>
    I got part of this from the internet, but here's a quick explanation. The root-layout part defines the whole area. Within this area you have regions. The first region defines the video region and you can give it any id. The origin of the screen is upper-left. fit="meet" means the the movie will be proportional to fit the whole movie. You can change it to other parameters (read the link from the last post). So here, three regions are defined. The first is for the movie (I used a slideshow from iPhoto), the second is for captions in the middle, and the third region is for the link region at the bottom of the screen. You can use any region as a link. Within these regions you place your movies, text, etc. (see the link for more types).
    You next place your types in the body:
    <body>
    <par>
    <!-- VIDEO -->
    <video src="slideshow.mov" region="videoregion" id="mov"/>
    <!-- CAPTIONS -->
    <textstream src="caption.txt" region="textregion" system-language="en" system-captions="on" title="english captions" alt="english captions"/>
    (a href="file://localhost/Users/kel/Desktop/linkapp" show="new")
    <text src="text.txt" region="linkregion" end="id(mov)(end)"/>
    (/a)
    </par>
    </body>
    video src says what type of object, slideshow.mov is the name of my movie. If you place the movie in the same folder as the smil file, you can use just its name like I did. Then you enter what region you want the movie in. The id="mov" part is to give this video a reference for later use. I used it to keep the text in the link area running until the movie ended. You don't need captions if you don't want, but if you do here's an example of my captions.txt file:
    {QTtext} {font: Arial} {justify: center} {size: 12} {backcolor:0, 0, 0} {timescale: 30} {width: 320} {height: 60}
    [00:00:00.00]
    Kelvin: Here is my movie.
    [00:00:04.15]
    {justify:left} {italic} Here is more text. {plain}
    [00:00:07.04]
    After 4 15/30 seconds the text changes.
    So altogether, I had five files in the same folder: the smil file (slidshow.smil - plain text), the movie (slideshow.mov), the caption text (caption.txt - plain text), and the text file for the link region's text (text.txt - plain text). The script application was on my desktop:
    "file://localhost/Users/kel/Desktop/linkapp"
    It's easy to get a local file url through applescript:
    set f to choose file -- the script app
    tell application "Finder"
    set the_url to url of f
    end tell
    and the the local file url is returned in the result.
    The movie needs work. I was playing around with the colors. blue is not a good background color.
    One thing I forgot to say is that you need to read more about the timing (duration). There are a lot of examples and tutorials on the Internet also. It's not that hard though. One thing you might have trouble with is getting repeats to work. I don't think they do.
    gl,

  • Help with moving contact info using Apple Script in Address Book

    Hi folks,
    I wonder if someone can help? I imported a few hundred contacts via a Gmail created vCard into my Address Book. The problem is that instead of inserting the email addresses into one of the email fields for each record, it has inserted the email address into the Notes field as follows: "EmailAddress: [email protected]".
    I would like help to write an Apple Script that will search my contacts in Address Book, find those with "EmailAddress:" in the notes field, cut the email address that follows it, and pastes it into the Work Email field, carries out the operation for the whole address book and saves the changes.
    Can anyone help me write a script for this. I've not used Apple Script before so this will be my first attempt!
    Thanks in advance,
    ayworld

    This should work:
    tell application "Contacts"
      activate
              set thePeople to every person whose note contains "EmailAddress:"
              set {oldTID, AppleScript's text item delimiters} to {AppleScript's text item delimiters, ":"}
              repeat with thePerson in thePeople
                   set nn to thePerson's note
                    make new email at end of emails of thePerson with properties {label:"Notes", value:text item 2 of nn}
              end repeat
      save
    end tell
    It will leave the entry in notes and make the label of the new email 'Notes"
    Normally when I post an AppleScript like this I tell the user to test it out before using it on the actual data but in this case I don;t know how you'd do that given there is only one Contacts and only one Contacts database.
    Just make sure you have a backup just in case. I tried it here on some dummy entries in my Contacts and it worked OK.
    Again this totaly relies on the data you presented. The Notes field has to be in the format
    EmailAddress:[email protected]
    for this to work.
    regards
    Message was edited by: Frank Caggiano - If you select all the text in the box, then right click and select Make new AppleScript the script will open in the AppleScript editor. Just make sure you get all the text it is easy to drop the first or last char when selecting.

  • Apple script hang up

    When i run an applescript it does it's job (runs a shell script) but then hangs up and i have to force quit it. Is there a shell script or apple script i could run to tell it to force quit without knowing the number of the running process? This is as i would like to not have to find out the process id number each time i run the script as it changes each time...
    thanks - 7;^')

    There are two elements here.
    First, AppleScript is, indeed, waiting for the process to finish before ending itself, so the first step would be to have AppleScript not wait for the process to end and return control immediately.
    In order to do that you need to add some addition elements to the shell command, specifically " > /dev/null 2>&1' before the trailing &, like:
    <pre class=command>do shell script "/System/Library/Frameworks/ScreenSaver.framework/Resources/ScreenSaverEngine.a pp/Contents/MacOS/ScreenSaverEngine -background >/dev/null 2>&1 &"</pre>
    These additional elements suppress the output of the command (which you don't care about anyway) and allows AppleScript to continue while the shell command continues to execute in the background.
    For the kill element there is an additional part, echo $!, you can use that returns the PID of the command just executed. You can store this and use it later to kill the process.
    This example launches the screensaver for one minute, then kills it.
    set myPID to do shell script "/System/Library/Frameworks/ScreenSaver.framework/Resources/ScreenSaverEngine.a pp/Contents/MacOS/ScreenSaverEngine -background &> /dev/null & echo $!"
    delay 60
    do shell script "kill " & myPID
    You could also use killall, but since this kills processes by name, not PID, you run the risk of killing other processes at the same time.

Maybe you are looking for

  • Updating a table using cursor is taking long time in oracle

    Hi, I am working on the oracle database 11gR2. I am trying update a table column which is newly added through cursor. below is the cursor. BEGIN      FOR lcur_tab IN (select l.LOGIN_ID as login_id, lt.ERROR_CODE as error_code from LOGIN l INNER JOIN

  • Problem while releasing invoice to accounting

    Hello, When I try to release a debit memo to accounting (VF02), the system throws the following error: Account type/account for invoice reference does not match item Message no. F5350 Any pointers on how to solve this please? Thanks, Shankar

  • Changing the notification status

    How to change the status of the notification programatically? I mean based on some scenario if i want to change the status of the notification of a person to "Closed" or "Open" or "Cancelled", how is this possible? Thanks

  • Error saying "Error in the module RSQL accessing the database interface"

    Hi, there is a standard program available for retrieving the assets for the given cost centres on the selection screen. Our requirement is instead of cost centre we have to retrieve the assets for the given cost centre group. We have to find all the

  • A working browser for OS X.3.9 needed.

    I am trying to find a browser that will work for me, but I never expected it to be such a problem. I have downloaded Firefox, Camino and Shiira. Of the three only Shiira works - both the Mozilla browsers quit as soon as they try to load a site (or as