Panther applescript question...

Hi everyone!
I know Panther is a bit old now...but hopefully someone can explain why this doesn't work:
tell application "Finder"
set theLocation to ((path to home folder as string) & "Desktop:testfile")
set theFile to (open for access file theLocation with write permission)
set theContent to read file (theLocation as string)
display dialog theContent
-- result is "9"
if theContent is "9" then
display dialog "OK"
end if
close access theFile
end tell
In this script it doesn't recognize that the value is the same (9) and never displays the "OK" dialog. However if I make a simple script like this it's no problem:
set theTest to "9"
if theTest is "9" then
display dialog "OK"
end if
Can someone please explain this? Thank you very much in advance...
Reg

Hi and thanks for the reply!
The test file is made from Script Editor...no external editors were used. It makes sense what you say...I was also thinking something like this but I couldn't figure it out. Yes in Leopard it's no problem as you said. Also, I think I made a mistake when I put (theLocation as string) it should just be theLocation. I was also trying to read as string and as number and no matter what I did it never read properly. I can make some more tests using your suggestions...just one thing...if I create the file using Script Editor how can I write it in such a way that it can be read. Can I write as Unicode text and read as Unicode text so it will come out the right way?
Thanks again so much,
Reg
Note:
Here is a more accurate post of the script...
tell application "Finder"
set theLocation to ((path to home folder as string) & "Desktop:testfile")
set theFile to (open for access file theLocation with write permission)
set eof theFile to 0
write "9" to theFile starting at eof
set theContent to read file theLocation
display dialog theContent
-- result is "9"
if theContent is "9" then
display dialog "OK"
end if
close access theFile
end tell
Message was edited by: Reggie Ashworth

Similar Messages

  • Panther FileVault question...

    Hi everyone!
    Ok here's my question...this is a basic command:
    tell application "Finder"
    get name of every item of folder "Application Support" of folder "Library" of Home
    end tell
    But this doesn't work in a FileVault Home folder in Panther. It does work in a FileVault Home folder in Tiger. Other variations of this command do work in a FileVault Home folder in Panther:
    tell application "Finder"
    get name of every item of Home
    end tell
    So I think it just depends on where you want to get the info? Does anyone have a work around for this? There must be a way to retrieve this info?
    Thanks in advance!
    Reg

    Hi again Niel!
    First the simple issue...What you suggested worked fine but when I plugged it into my AppleScript Studio script it (maybe together with other lines of script?) caused Panther (FileVault) to crash. My script was in "tell Finder" blocks which I had to place end tell or tell me to make this work, that's when it crashed. Anyways I removed "alias" from the 2nd line and was able to leave it in my Finder tell block and it worked fine. So now I can say I worked on it too!
    But I noticed I will have additional problems because in my script I take that list of filenames (which now works great!) and I do a repeat block with that list looking for a name that meets certain criteria. If I find a name this is what I do:
    tell application "Finder"
    set the_file to (every item of folder "application support" of folder "library" of home whose name is i) as alias
    set the_container to container of (every item of folder "application support" of folder "library" of home whose name is i) as alias
    end tell
    There might be more instances where I look through this folder with the Finder and it won't let me no matter how I word it. Do you have maybe a guideline I can follow? Does it make sense what I'm explaining? So basically from a list of names if I find a file I'm looking for I use the Finder to get additional info such as the full path and the container and maybe others too...
    Thanks for all your help Niel!
    Reg

  • Ical Applescript questions and missing commands

    This is an advanced itunes question....
    I am using itunes with ical and applescript to run a radio station.   I have used alot of things from Doug Adam's and taken some things past where i can get help.   I am using itunes 7...and os X 10.5.8 .   i am also using ical buddy, gcal(for xml) and a few other neat little tricks.  
    I have run into a few technical problems and was wondering if anyone knew how to fix them.
    1 Problems happen:    is there a way to disable ALL pop-up warnings in itunes........not just sync, or playlist warnings, but all errors that require someone to click......
    2 is there a way to Toggle (on/off) itunes soundcheck in the preferences when you set a playlist to play with an applescript
    Thank you,
    Jacob Bouchard
    www.wfku.org

    I  have updated to Itunes 10.4, and have encountered a whole new set of problems
    1. (solved)  the popup warnings in Itunes 10.4 are gone.   I have a good backup applescript that forcequits the applescript app, or forces a return Key press into the warning window.   It works but i want to make it better
    2. (solved)   I have solved the soundcheck problem with an applescript (its not pretty, but does the job)
    NEW PROBLEM:
    upgrading to Itunes 10.4 removed the *Smart shuffle features that were in Itunes 7.6.   (this is much different from smart playlists)  
    I NEED THAT FEATURE
    Can someone at apple please give me the Hexidecimal code  i need to replace in the com.apple.itunes prefs file that will re-orient the smart-shuffle  to *shuffle "Songs"  with "least likely artist repeat" Setting
    Thanks in Advance,
    Jacob
    *Removed in iTunes 8
    also as a sidenote iCal version 4.04 is doing something shady when i export the event information.   It feeds garbage into my code which creates errors apparently at random.   The problem is resolved with earlier and later releases of iCal (That i cannot use becuase i have a Macbook pro 2006 Intel Duo core which will not take the lion operation system)   Sometimes it feeds garbage after the ical information that my shellscript is requesting

  • ICal questions, maybe going into applescript question

    Hello, I am trying to create a recurring ICAL event with different titles for a time period.  It is simple, I want on monday of everyweek tor 7 monthes to read, week1, week2, week3 etc.  Is this possibe in ICAL, or possible via applescript (beginner applescripter)? 
    Thanks!

    All do-able in DVDSP... and pretty easy to do as well.
    You can create the menus with links to the chapters in your track (which will play the chapter and then continue), you can set the chapters into stories and point the menu buttons to those instead and you can set each story to go back to the right menu.
    You can then point a play all button at the track itself, which will then play all... which hopefully answers mish's question as well as yours.
    Much of this is in the tutorials that come with DVDSP, and it is well worth your time going through those if you haven't already moved up to DVDSP. There is a lot of help available on this forum as well, mind you!

  • Thinking Home Home Automation Applescript Question

    Hello,
    I have a quick question on writing an applescript for Thinking Home 2.02. I'm just looking to do a few basic functions like turn off device "x" turn on device "y" etc. Any ideas? I looked in the dictionary for the application but I keep getting the error that it "can't get the device "b2" of controller "usb". Any ideas? Thanks again!
    tell application "Thinking Home"
    activate
    tell controller "USB"
    turn on device "B2"
    end tell
    end tell

    Looking at the dictionary, it seems that you should be using something like:
    turn on device address "B 2"
    In other words you're missing the 'address' property. Without that it is assumes you're providing a name which is more likely to be something like "Living room lamp" or "Coffee machine".

  • Applescript question about variables

    I have a command in AppleScript that goes like this
                                  set focus check box "/app/con[0]/ses[0]/wnd[0]/usr/chk[1,12]"
    I would like to make the "12" a variable, and pass a new value by putting it in a loop
    Something like
                                  set focus check box "/app/con[0]/ses[0]/wnd[0]/usr/chk[1,x]"
    Any suggestions to how to pass variable x in a string?
    Thank you for your time

    "/app/con[0]/ses[0]/wnd[0]/usr/chk[1," & x & "]"
    Proof:
    set x to 12
    "/app/con[0]/ses[0]/wnd[0]/usr/chk[1," & x & "]" = "/app/con[0]/ses[0]/wnd[0]/usr/chk[1,12]" --> true
    Message was edited by: Pierre L.

  • Another mail applescript question...

    Hi again!
    I just posted a topic about how to auto-reply in Mail with an attachment by using Applescript and rules in Mail. I figured I should be able to do this via Applescript but I am having a problem. Nevermind the attachment for the moment but I can't even get a message to send. Take this example:
    tell application "Mail"
    make new outgoing message with properties {visible:true, subject:"My Subject", content:"My Body"}
    end tell
    If I run this in Script Editor it prepares a new message (although not yet sent). If I attach this to a rule in Mail nothing happens. As a test I changed the script to simple say display dialog "test" and it does work. So my rule in Mail.app is ok but when I use this simple script above nothing happens. I hope this makes sense and someone can help me to set up a rule in Mail that triggers a Applescript which will send a message...thank you!
    Reg

    Hi again VK!
    Yes I do understand and maybe it's an error on my part but I couldn't get it to work. What I'm doing now is I use an applescript to gather the sender of the incoming message and save it to Address Book. Then I tell that applescript to launch a separate applescript saved as app to send a message to that same person using the info stored in Address Book. It's a bit sloppy too but it works. Occasionally though it seems to send out a blank message??? I will try to experiment more when I get the chance. Hopefully Apple will just fix this bug in 10.5.4???
    Thanks again,
    Reg

  • Applescript question

    the problem
    i have various photographers taking photos raw and jpegs, showing the jpegs to the client to make there order and the raw files are left on the data card and later transfered at the office for processing
    i made a small script to transfer the all files on the cf card to g5 then place them in a new dated folder then separate the files from raw or jpeg and place them in a folder of each kind
    is there a way of making a list of files (text) made by the person showing the jpegs which i can insert or command the script to get a reference to the other script to then select only the raw files needed
    the script i made is this i need an addition to read a text file of reference of raw files needed to process
    property jpgs : {"JPG"}
    property Raw-files : {"CR2"}
    set yesterday to ((day of (current date)) - 1 as string)
    set raw to "Canon Raw Paqui" as text
    set small jpg to "Canon jpg Paqui"
    set p to "print paqui"
    tell application "Finder"
    activate
    make new folder at folder "july" of folder "2007" of folder "photos" of disk "LaCie Disk" with properties {name:yesterday}
    set z to folder yesterday of folder "july" of folder "2007" of folder "photos" of disk "LaCie Disk"
    delay 2
    make new folder at z with properties {name:raw}
    make new folder at z with properties {name:smalljpg}
    make new folder at z with properties {name:p}
    set a to "EOS_DIGITAL:DCIM:769-CANON:"
    with timeout of 2000 seconds
    duplicate every file of folder a to z
    end timeout
    set b to folder raw of z
    set c to folder smalljpg of z
    set these-Files to every file of z whose ¬
    name ends with "CR2"
    move these-Files to b
    set thesejpgs to every file of z whose ¬
    name ends with "jpg"
    move thesejpgs to c
    set d to yesterday
    repeat
    display dialog "find the file !" default answer ""
    set fc to text returned of result
    tell application "Finder"
    set x to folder raw of folder d of folder "july" of folder "2007" of folder "photos" of disk "LaCie Disk"
    get x
    set z to every file of x whose name contains fc
    set y to the count of z
    repeat with i from 1 to y
    set photo to item i of z as alias
    move photo to folder p of folder d of folder "july" of folder "2007" of folder "photos" of disk "LaCie Disk"
    end repeat
    end tell
    end repeat
    end tell
    thanks

    Suggest you repost to the AppleScript forum: http://discussions.apple.com/forum.jspa?forumID=724 where you should get an answer.

  • Various AppleScript Questions

    Hi all,
    I am a newbie to AppleScript, so please be patient.
    I am trying to write a script that automatically performs the following actions which I have to do regularly to a spreadsheet I get:
    Delete the first two rows
    alter the top row to be a title row
    do three certain "search and replace" actions (replace "I1" by "1", case sensitive, full words only)
    categorize and sort by two columns
    set one certain column to "number" format
    apply category sums to a certain column
    Optionally: move some columns to a different position
    I am now as far as this (by reading some posts in this forum):
    tell application "Numbers"
    activate
    set myDocName to name of document 1
    tell document 1
    tell sheet 1
    tell table 1
    remove row 1
    remove row 1
    -- How to change the top row to be a title row??
    end tell
    end tell
    end tell
    end tell
    I suspect that the next things I need have something to do with changing the properties of rows and columns, but I did not find an example of the necessary syntax. Can anybody provide a hint? A link to some documentation would be really nice!
    Thanks a lot
    Wolfii

    Wolfii wrote:
    Hi all,
    I am a newbie to AppleScript, so please be patient.
    I am trying to write a script that automatically performs the following actions which I have to do regularly to a spreadsheet I get:
    Delete the first two rows
    alter the top row to be a title row
    do three certain "search and replace" actions (replace "I1" by "1", case sensitive, full words only)
    categorize and sort by two columns
    set one certain column to "number" format
    apply category sums to a certain column
    Optionally: move some columns to a different position
    I am now as far as this (by reading some posts in this forum):
    I suspect that the next things I need have something to do with changing the properties of rows and columns, but I did not find an example of the necessary syntax.
    You suspect wrongly
    If you insert in your code the instruction
    get properties of row 1
    you will discover that there is no property linked to the row status.
    Can anybody provide a hint? A link to some documentation would be really nice!
    THE source of information is the application's AppleScript's dictionary which you may access thru
    Script Editor > File > Open a dictionary…
    What you asked can't be done with vanilla AppleScript.
    It would require the use of GUI Scripting.
    http://www.apple.com/applescript/uiscripting/
    Defining headers is simple:
    Setting cells format is simple too.
    The dictionary states:
    format (automatic/checkbox/currency/date and time/fraction/number/percent/pop up menu/scientific/slider/stepper/text) : The cell format of the range's cells.
    Your Search/Replace request may be done thru vanilla AppleScript but it would be long and awful.
    AppleScript is unable to get the formulas. It get only the values so, to fit your request you need to:
    +scan every cell+
    +get and save the cell's format+
    +set the cell's format to text+
    +get the cell's value.+
    +if it contains the word l1, replace it by 1+
    +if you replaced something, set the cell's value to the new string+
    +reset the cell's format to it's original one+
    +continue the scan.+
    I didn't tested but, according to the dictionary, sorting thru vanilla AppleScript can only be done with a single key column:
    sort v : Sort the rows of the table.
    sort table
    by column : The column to sort by.
    [direction ascending/descending]
    [in rows range] : Limit the sort to the specified rows.
    Other tasks would be more difficult because you must find a way to GUIscript dialogs available thru Inspectors
    As far as I know, some request can't be responded because there is no tool to do that (we can't drag column label as requested to move a column)
    Have fun.
    on run
    set nbRowsToRemove to 2
    set nbHeaderRow to 1
    my activateGUIscripting()
    tell application "Numbers"
    set theApp to name
    set myDocName to name of document 1
    tell document myDocName to tell sheet 1 to tell table 1
    repeat with i from 1 to nbRowsToRemove
    remove row 1
    end repeat
    my selectSubMenu(theApp, 6, 10, (1 + nbHeaderRow)) (* define header row(s) *)
    set rowMax to row count
    set column6 to (name of cell 1 of column 6) & ":" & (name of cell rowMax of column 6)
    set format of range column6 to percent
    end tell
    end tell
    end run
    --=====
    on activateGUIscripting()
    tell application "System Events"
    if not (UI elements enabled) then set (UI elements enabled) to true (* to be sure than GUI scripting will be active *)
    end tell
    end activateGUIscripting
    --=====
    on selectSubMenu(theApp, mt, mi, ms)
    (* Call a 2nd level menu (submenu) *)
    tell application theApp
    activate
    tell application "System Events" to tell process theApp to tell menu bar 1 to tell menu bar item mt to tell menu 1 to tell menu item mi to tell menu 1 to click menu item ms
    end tell -- application theApp
    end selectSubMenu
    --=====
    Yvan KOENIG (from FRANCE mardi 5 mai 2009 16:55:46)

  • Safari Applescript Question

    I've used other scripting languages but never AppleScript. If anyone can help me with the right syntax for this simple script I'd appreciate it.
    I want this script to:
    Open a URL
    If the page contains Phrase A, show a popup window with a message and then exit.
    If the page contains Phrase B, show a popup window that says how many times Phrase B occurred in the page, and then exit.
    Also, how do I assign a custom icon to an AppleScript in the dock?

    Use a script such as:
    tell application "Safari"
    open location "yourURL"
    set string_1 to "Phrase 1"
    set string_2 to "Phrase 2"
    set message_1 to "Message 1"
    set the_text to (text of document 1)
    set the_counter to 0
    if (offset of string_1 in the_text) is not 0 then
    display dialog message_1 buttons "OK" default button "OK"
    return
    end if
    if (offset of string_2 in the_text) is not 0 then
    repeat
    set the_counter to the_counter + 1
    set the_text to items ((offset of string_2 in the_text) + (count string_2)) thru -1 of the_text as string
    if (offset of string_2 in the_text) is 0 then
    display dialog "The phrase " & string_2 & " occurs " & the_counter & " times."
    return
    end if
    end repeat
    end if
    end tell
    replacing the text inside the quote marks of lines 2 through 5 as desired.
    (27040)

  • Another AppleScript question

    How would one make a password, let me explain more about this,
    So pretty much I have it where you enter and set a password; it's all good.
    So my question was how would I make it so it opens up a dialog after you set it telling you to enter the password you just set, if it's wrong it'll tell you to write it again, if it's right it'll open up whatever I put, here is my current code.
    property firstRun : true
    if firstRun then
        set pass to text returned of (display dialog "Choose your password." with title "Pass Select" default answer "" buttons {"Cancel", "Select"} default button 2 with hidden answer)
        set firstRun to false
    end if
    Thanks to everyone who replies to this and helps me.

    Here:
    property firstRun : true
    property the_pass : ""
    if firstRun then
    set the_pass to text returned of (display dialog "Choose your password." with title "Pass Select" default answer "" buttons {"Cancel", "Select"} default button 2 with hidden answer)
    set firstRun to false
    else
    set pass to text returned of (display dialog "Provide the password." with title "Pass Select" default answer "" buttons {"Cancel", "Select"} default button 2 with hidden answer)
    repeat
    if pass is the_pass then
    exit repeat
    else
    set pass to text returned of (display dialog "Incorrect password." with title "Pass Select" default answer "" buttons {"Cancel", "Select"} default button 2 with hidden answer)
    end if
    end repeat
    end if
    (102371)

  • I have an Applescript question

    I have never written an Applescript before, so I hope this isn't a tough task.
    I have a pile of Macs on a Windows network (active directory). When an AD user logs in, their network folder mounts on the dock. What I want to do, is write an applescript (or if one already exists somewhere, i'd be much appreciative if someone could point me to it), so that when an AD user logs in, an alias pointing to that user's network folder is created on the user's desktop. That's it.
    Can someone help me??

    I'm hoping there is a variable for the UNC path that I can use in Applescript. Is there?
    I'm a Windows guy lost in the Mac world

  • An applescript question

    Ok i have a problem. I had spaces setup with 3 rows and 3 columns, and had some applications bound to certain spaces. Somehow my spaces got reset to 2 rows and 2 columns, but the application bindings remain. As a result, when I open system preferences, it tries to open in a space that is no longer there. System Preferences opens but does not show up. When I hit my spaces button, I can see the preferences but cannot click them. I believe a quick fix would be to use applescript to re-assign my application binding for system preferences to a different space, say space 1. Sadly I dont know applescript. Can someone write me a script that would do this, so i can access my system preferences again.

    UnlikelyHero432 wrote:
    ok first i dont have a file called com.apple.dock.plist on my computer,
    you must be looking in the wrong Library. I'm talking about Library in your home directory not Library at the top level of the hard drive.
    and second, Dock is not recognized as a valid process.
    what do you mean? you don't have a Dock?!

  • Applescript question: can I superimpose images?

    I couldn't find an Applescript forum here... so I thought I'd try here (hoping some clever prson is lurking and just happens to come accross this post!)
    I want to place a PNG over another set of images
    The PNG has a transparent background
    I want to place on the bottom right hand side of all images
    Is this something I can do with Applescript?
    I also need to resize and save files as jpgs, coming from png's
    I assume this is no poblem from the brief bits I've read
    I was going to use ImageMagik
    But I won't need to do anything else... and would rather avoid installing something that doesn't need to be installed (if I can use Applescript)
    Just looking for: yes you can + any sample scripts would be great (or is that asking for too much!)
    Thanks
    Omar

    Yes you can lower the opacity of the top image and also add a layer mask to the top image layer and hide parts of in to shoe the bottom image more is areas

  • Simple Automator+Applescript Question

    EvoCam has a feature where when an event happens, such as motion, the app quits, starts, etc., it can run an AppleScript. I'd rather use automator, because it's just easier to understand for me. I wrote and automator workflow. However, as I mentioned, EvoCam only runs AppleScripts. Can someone give me an AppleScript to run an Automator workflow? I assume there is a way to run it. If not, I'll just save it as an app and have applescript run the app.
    iMac Intel Core Duo 17"   Mac OS X (10.4.8)   iPod mini 2nd Gen 4GB

    I was able to find the answer by using Script Editor's record function and then modifying the code it gave me.
    iMac Intel Core Duo 17"   Mac OS X (10.4.8)   iPod mini 2nd Gen 4GB

Maybe you are looking for

  • How to write a sql query to calculate weights using CTE

    Hi guys, want some help using a CTE to generate data using recursive SQL - input data in table A to be transformed into table B shown below Table A Instru_id_index     instru_id_name    instru_id_constit  con_name   weight         56                 

  • Windows Vista Ultimate installed via Boot Camp?

    Can install Windows Vista Ultimate 64bit using the latest version of Boot Camp on OS X Lion 10.7.4, or is it not supported? This article is not clear: http://support.apple.com/kb/HT1461

  • HT1379 Problem with my Macbook Pro 13" 2011 usb port.

    I cant get my usb port (closest to the shift key) to recognise anything. I had my external hard drive connected to the port and was transfering files at the time when my usb harddrive fell and became disconnected. I got the error on my screen that i

  • SQL*Loader - How to set numeric seperator in Controlfile for float external

    I need to use "FLOAT EXTERNAL" instead of "to_number" and I want ensure that the correct numeric separator is set. At "to_number it look like: col1 "to_number(:col1,'99999999999999999.99999999999999999','NLS_NUMERIC_CHARACTERS=''.,''')") But how shou

  • Copy and paste problem with regions

    I've noticed that occasionally, when I copy and paste a region within the same track, I sometimes paste twice (directly on top of the other region). Or at least that's the end result. When I realize this, I go to delete the region and then there's a