Shellscript in Applescript

I made a shell script that works until one point where the Escape key needs to be pressed. Does anybody know how to make applescript make a keystroke while inside of the shell script???

theAnimator: I've followed you through several threads apparently trying to solve a simple problem, but it seems you are getting lots of partial answers and you are now trying to piece them together, but the real solution is much simpler. Instead of trying to turn that interactive process (where you need to type the escape character) into a non-interactive one, the interactive process that you're trying to adopt (perhaps with expect) was dubious advice. That problem could have been solved directly with a simpler non-interactive solution that doesn't rely on the keyboard.
For example, if you can put the lines you want to insert into a file, "finsert", and you want to insert those lines between lines 12 and 13 of file fdata, the following Unix shell script would do that:
# make backup
cp fdata fdata.bak
# copy first 12 lines
head -n 12 fdata.bak > fdata
# copy insert text
cat finsert >> fdata
# copy remainder
tail -n +13 fdata.bak >> fdata
Note the distinction between > and >> in the script.

Similar Messages

  • Mail  shellscript or applescript

    There's a command in Mail to see the messages on the pop3 server, and the possibility to remove selected message from server.
    How can i perform the same command whith AppleScript or a Shellscript and add it to a rule?
    Thank You

    You can do this with AppleScript, using a Mail Rule to call the Script.
    Repost your question in forum http://discussions.apple.com/forum.jspa?forumID=724
    One of the AppleScript gurus over there will be able to give you the exact script you need.
    Hope that helps.

  • Applescript help: using commandline within applescript

    I'm trying to use applescript to take the results from a shell script and then put the results into the finder comments of the file. I believe I can use:
    do shell script "/Users/wesM/Documents/Development/AVWSamples/test.sh"
    to run the script, but I can't get it to work. test.sh is and executable file, and has the following line in it:
    mdls -name kMDItemCodecs -name kMDItemPixelWidth -name kMDItemPixelHeight 19Never.mov | awk '{ print "Codec "$1}' > out
    The script works fine. I want to take the results file (out), and then put it into the finder comments, I'm guessing with:
    set comment
    Is this possible? Can I get the filename to a shellscript from applescript?
    Is there a better/easier way to do this?
    Thanks for any help.

    I should have read the mdls command you used. i just copied and pasted it. you need to provide the correct path to the movie file. you didn't which is why the command failed. there is nothing to escape in that name so it's not an issue. and yes you can turn it into an application so that when you drop a file onto it it will automatically do this to all dropped files.
    <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 open these_items
    tell application "Finder"
    repeat with this_item in these_items
    set fpath to quoted form of POSIX path of this_item
    set comment of this_item to do shell script "mdls -name kMDItemCodecs -name kMDItemPixelWidth -name kMDItemPixelHeight " & fpath
    end repeat
    end tell
    end open</pre>
    save this as an application. if you want the original shell command use that in the above instead.

  • Batch merging two TIFF files into one

    I have a lot of portrait B5-size TIFF files that were scanned from paper documents and I plan to scan more.
    I want to merge every two of these files into landscape B4-size TIFF files.
    I want to do this by a batch job.
    What is the best way?
    Are there any command-line tools to do this job?
    I do not have Adobe package software. Instead I installed MacGimp.
    Although I have some experience with shellscript and Applescript,
    I'm new to Script-Fu.
    I made a GUI script for the application Preview that reads a multi-page TIFF file and saves as a PDF file with 2-UP layout. This method has two flaws:
    (1) Preview aborts for large files.
    (2) Resulting PDF file is more than five times as large as original TIFF file.
    Namely, 40-page, g4-compressed, 400KB TIFF file results in 2.5 MB PDF file.
    Maybe, the Preview does not make inheritance of TIFF compression.
    So I decided to make multi-page TIFF files of 2-UP layout.
    Thank you for reading.
    iMac G4   Mac OS X (10.3.9)  

    Self-solved.
    convert file1.tif file2.tif +append result.tif
    The command-line tool `convert' can be installed by Fink
    as a part of ImageMagick.
    iMac G4   Mac OS X (10.3.9)  

  • Applescript oe shellscript to delete config file?

    Hi All,
    pls suggest how do i delete config file with permissions, with my scripts .cfg file is not deleting. I tried with applescript and shell script both, but its not working.. and also its not asking for permissions as well..
    tell application "System Events"
        delete  file "/Library/Application Support/Macromedia/abc.cfg"
    end tell
    do shell script "rm -f /Library/Application Support/Macromedia/abc.cfg"

    If you use 'do shell script' you'll need to escape the spaces in path, either by quoting the entire path, or by using backslashes:
    do shell script "rm -f '/Library/Application Support/Macromedia/abc.cfg'"
    The 'pure' AppleScript solution likely doesn't work because System Events isn't used to handling files. Try asking the Finder to delete the file instead.
    Of course, both methods assume you have sufficient privileges.

  • 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

  • Uploading a File with AppleScript via JavaScript

    Hi everybody,
    being new to AppleScripting and JavaScripting I'm faced with the following problem:
    Is it possible to make AppleScript to input the path for a file to be uploaded via JavaScript? If yes, what should be the correct Path Format and how to wrap it up the JavaScript action into AppleScript? I've tried a few comands but to no success.
    On the webpage in question, there's a "Choose" button, that is defined as follows:
    <input type=​"file" class=​"gwt-FileUpload" name=​"swfFile">​
    I've been trying to use the following syntax:
    do JavaScript "document.getElementsByName('swfFile')[0].value('Macintosh HD:Users:myaccount:Desktop:Scrapbook:!动画.swf')" in document 1
    as well as this one, where the Path is definitelly understood by shellscript:
    do JavaScript "document.getElementsByName('swfFile')[0].value('/Users/myaccount/Desktop/Scrap book/!动画.swf')" in document 1
    The name of the file is (and must remain) in chinese, but for testing purposes I have also tried files with english names, without success.
    Currently I'm using a solution with JavaScript comand:
    do JavaScript "document.getElementsByName('swfFile')[0].click()" in document 1
    to click the finder  window to browse for the file, and manipulating  keystrokes by using System Events to find the right file, but it's not  infallible with a number of files and it's hardly an ellegant sollution.
    Any idea what I'm doing wrong?
    Cheers!

    @twtwtw
    the do JavaScript "document.forms[0].submit()" command didn't work, so I kept the original way of submitting by clicking the button. The submitting part works, but not the input file part.
    That's the code I used
        tell application "Safari"
            do JavaScript "document.getElementById('gwt-uid-13').value='on'" in document 1
            do JavaScript "document.forms[0].elements['swfFile'].value=" & "'" & SWFFilePath & "'" in document 1
            do JavaScript "document.getElementsByClassName('gwt-SubmitButton')[0].click()" in document 1  
            delay 1
        end tell
    with SWFFilePath set as the POSIX path as well as the default file format
    Macintosh HD:Users:myaccount:Desktop:Scrapbook:!动画.swf'
    but it did not work.
    If you've got the time, feel free to upload an .swf. The service is free and the server delats uploaded files after 15 min. (if you don't have any, you may try an empty .txt file instead - it won't get converted, but the point is just to get it into the input box).
    In the meantime, I'll have a look at adayzdone's suggestion. It's not perfect (the downside being that it requires the window to be active, so I can't run the script in the background or with my screensaver & password on), but it's still more reliable than my sollution with navigating arrowkeyes.

  • Do a perl command from applescript

    I'd like to use Perl from AppleScript for text replacements. The snippet below works, however when the var haystackString starts to include apostrophes, this fails. I tried using AppleScript's "quoted form of" on haystackString however it fails I think because the shell command I'm using needs single quotes to enclose the commands being executed by Perl. Any tips? Thanks, Ted
    set haystackString to "this this"
      set findString to "this"
      set replaceString to "that"
    set shellscript to ("perl -e '$s=\"" & haystackString & "\";$toFind=\"" & findString & "\";$replaceWith =\"" & replaceString & "\";$s =~ s/$toFind/$replaceWith/g;print $s;'") as string
      set testString to do shell script shellscript

    Hi,
    Ted Fitzpatrick wrote:
    however it fails I think because the shell command I'm using needs single quotes to enclose the commands being executed by Perl. Any tips? Thanks, Ted
    Yes, that's right.
    Solution, use the arguments:
    set haystackString to "can't  can't"
    set findString to "can't"
    set replaceString to "that's all"
    set args to (quoted form of haystackString) & " " & (quoted form of findString) & " " & quoted form of replaceString
    set testString to do shell script "perl -e '$s=\"$ARGV[0]\";$s =~ s/$ARGV[1]/$ARGV[2]/g; print \"$s\"' " & args

  • Applescript Droplet to copy all dropped Items to some place...?

    Hi !
    Im trying to create an Applescript, as a Droplet, that copies all Files or Folders that i drop on it, to a predefined folder.
    This is what i did:
    on open theFiles
              tell application "Finder"
                        copy theFiles to folder "Macintosh HD:Users:MYUSERNAME:SomeFolder"
              end tell
    end open
    I've tried several ways but they all end up with error messages, or with only working on one file,
    but not in 2 or more files.
    I already had a look on shell commands like this "-cp" shellscript, but i dont know how to use them.
    Helpz please.
    Regards
                             DaNylz

    Take a look at the Finder's scripting dictionary.  The copy command is not implemented yet, and when/if it is, it will be for the clipboard.  The command you are looking for is duplicate (or move).

  • Applescript + Bundled Script

    I have a shell script that I want to be portable for my team here at work. The problem is, when I send the script via email (which is how I want to distribute), it strips it's executable attributes.
    So I was thinking- Bundle the shell script into the Applescript.app contents/resources then launch:
    ## Make file executable ##
    do shell script "chmod 755 /Users/user/Desktop/Applescript.app/Contents/Resources/Scripts/shellscript.comm and"
    ## Then launch the script- I need terminal to launch and be forefront for user input required by the shell script ##
    tell application "Terminal"
              open "/Users/user/Desktop/Applescript.app/Contents/Resources/Scripts/shellscript.com mand"
    end tell
    ## Terminal can then take it from there
    Here's the problem- those absolute file paths don't work from a portability standpoint. Is there a way for me to reference the path of the resource files dynamically? When I send it to John Smith, it is still searching for the file path that I created originally on my system.

    I actually expanded the shell script a bit, having trouble getting the suggested quote changes to work with the expanded script (works well with the single chmod command). Is this correct?
    do shell script "stat -l '" & (POSIX path of (path to me)) & "Contents/Resources/Scripts/shellscript.command | cut -c 1-10 | grep -e -rwxr--r-x || chmod 755 '" & (POSIX path of (path to me)) & "Contents/Resources/Scripts/shellscript.command'"

  • Shell commands in applescript noob

    Hi all this is my first post in these forums and I come seeking help with a certain script I'm writing for my current college job. The purpose of the script is to install creative cloud from a server and this is as far as I've got. First I can get as far as setting the correct directory in the server by doing:
    do script "cd /Volumes/applications/Mac/'Adobe Creative Cloud'/'Enterprise - enduser'/Build"
    now when I press run the terminal screen pops up just fine with no errors in the right directory. However I've been reading up that to do other commands in the same shell I must do do shell script. When doing this however terminal doesn't do...anything. The reason why I was trying this is because my next command would be initiating the install which is the command:
    "installer -verbose -pkg 'enterprise_Install.pkg' -target /" with adminitrator privilages
    Now my question is how would formulate this within applescript? Thanks.

    do shell script "cd /Volumes/applications/Mac/'Adobe Creative Cloud'/'Enterprise - enduser'/Build ;  installer -verbose -pkg 'enterprise_Install.pkg' -target / with administrator privilages"
    You got the double quote in the wrong place.
    do shell script "cd /Volumes/applications/Mac/'Adobe Creative Cloud'/'Enterprise - enduser'/Build ;  installer -verbose -pkg 'enterprise_Install.pkg' -target / " with administrator privilages
    It is easier to diagnose problems with debug information. I suggest adding log statements to your script to see what is going on.  Here is an example.
        Author: rccharles
        For testing, run in the Script Editor.
          1) Click on the Event Log tab to see the output from the log statement
          2) Click on Run
        For running shell commands see:
        http://developer.apple.com/mac/library/technotes/tn2002/tn2065.html
    on run
        -- Write a message into the event log.
        log "  --- Starting on " & ((current date) as string) & " --- "
        --  debug lines
        set unixDesktopPath to POSIX path of "/System/Library/User Template/"
        log "unixDesktopPath = " & unixDesktopPath
        set quotedUnixDesktopPath to quoted form of unixDesktopPath
        log "quoted form is " & quotedUnixDesktopPath
        try
            set fromUnix to do shell script "sudo ls -l  " & quotedUnixDesktopPath with administrator privileges
            display dialog "ls -l of " & quotedUnixDesktopPath & return & fromUnix
        on error errMsg
            log "ls -l error..." & errMsg
        end try
    end run

  • New Applescript version breaks old code

    Hi there,
    First off, I'm not an Applescripter, but I have one script I wrote a few years back (with help from kind people on the net) to generate and save tiny applications which, when called from within an Adobe Flash executable, would open the required file using the Mac OS native application associated with them (i.e a doc file wouldbe opened by Word if installed, TextEdit if not...)
    It used to run fine on my old Powerbook G4 on an old version of AppleScript, but times change and, one whizzy Intel processor later, I'm trying to get the same script running on OS 10.8 with AppleScipt 2.5.1, with varied results.
    Basically, what the script should do is read a comma delimited file in the same folder as the script, called 'fileNames.csv' which contains the names of all the files that I want the tiny apps to open. Each item will then have its own file created by the AppleScript, named after each item, which get saved in an pre-existing folder in the same directory as the script and fileNames.csv file, called 'fscommand'.
    The example of the fileNames.csv file I'm having issues with:
    yr2_unit_1_tn.doc,yr2_unit_2_tn.doc,yr2_unit_3_tn.doc ... etc up until  yr2_unit_20_tn.doc
    The script always used to work fine, but the new version of AppleScript seems to have broken it. When I run it now, it creates all the .app files up until 'yr2_unit_11_tn.doc.app' but then stalls in 'Running...' mode in the AppleScipts editor, and refuses to save apps for the final nine files in the .csv file.
    It still runs ok from an older AppleScript editor (2.2.1) but this only saves PowerPC applications, which won't run on Intel Macs. And this would be me running away from the problem, rather than attempting to solve it ;-)
    I'm thinking it's a filename issue, as it always seems to break when attempting to save "yr2_unit_11_tn.doc.app" when "yr2_unit_1_tn.doc.app" already exists in the 'fscommand' folder. If I create a new 'fileNames.csv' file which only contains ten entries from 'yr2_unit_11_tn.doc' to  'yr2_unit_20_tn.doc', and run the script to an empty 'fscommand' folder, it processes all the files fine. It just won't do all twenty entries from 1 to 20.
    Here's the script. I know I'm doing something really stupid here, but as a rock bottom novice AppleScripter, I can't see the error, or why it would work in one version of AppleScript and not another. I can post a link to the zipped files if this is any help in solving it. Thanks in advance for any help! :-)
    tell application "Finder" to get folder of (path to me) as Unicode text
    set cwd to result
    set fileRef to open for access alias (cwd & "fileNames.csv")
    set theList to read fileRef using delimiter ","
    close access fileRef
    set theFolder to alias (cwd & "fscommand")
    set theFolderPath to theFolder as string
    #Create the .app files and save them in theFolder
    set NL to ASCII character 10
    tell application id "com.apple.ScriptEditor2"
    launch
              repeat with theItem in theList
                        set x to make new document
                        set x to the front document
                        set theCharacters to characters of theItem
                        set theReversedCharacters to reverse of theCharacters
                        set theReversedFileName to theReversedCharacters as string
                        set theOffset to offset of "." in theReversedFileName
                        set theReversedSuffix to text 1 thru (theOffset - 1) of theReversedFileName
                        set theSuffix to (reverse of (characters of theReversedSuffix)) as string
                        set the text of document 1 to "tell application \"Finder\"" & NL & "activate" & NL & "set cwd to get folder of container of (path to me) as Unicode text" & NL & "open file (cwd & \"assets:" & theSuffix & ":" & theItem & "\")" & NL & "end tell"
      compile document 1
                        set file_path to theFolderPath & theItem & ".app"
                        save document 1 as "application" in file file_path
      close window 1
              end repeat
    end tell

    That seemed to be it. I put a tiny delay in between saving the document and closing the window and the file runs smoothly through all 20 items.
    compile document 1
    set file_path to theFolderPath & theItem & ".app"
    save document 1 as "application" in file file_path
    delay 0.3
    close window 1
    Never thought that I'd reach the day where I was trying to slow the computer down to process something more carefully :-D

  • Applescript to suck ical dates into iweb

    I was referred to this forum from the iweb forum (http://discussions.apple.com/thread.jspa?threadID=2513935&tstart=0).
    Here's what I would like to do: I am an athletic director and would I have entered all of my school's athletic contests into iCal. I would like to set up something in which iWeb can pull the events out of iCal (I have mobileme) into a "week at a glance" type of display on our athletics page (made with iweb). Ideally it would automatically update so that as events are completed, the next events would show up. I don't want to embed a calendar.
    I want something that looks like the table on the right of this page: www.twu.ca/athletics.
    Is there an applescript that could help me pull dates from iCal into a text box in iWeb?

    Hi,
    You may be able do this with an Applescript. However there is not enough information supplied to know.
    How are ther events formatted in iCal? Do they contain the full name of the person? Do they say how old they are? Are the people already in Address Book, or would they all be new cards?
    Best wishes
    John M

  • New bee looking for applescript help with text edit app

    I have a huge text files (20+) , I want to find a list of words like weather, farmers, ploughing. I want to find these words one at a time, as my text file is 250+ Mb in size.
    I want applescript to count the how many times each word appears in the text.
    Paste that occurrence of word into an spreadsheet file in a row named after text file , and in a column named weather, farmers, ploughing.
    Please help.
    Thanks much.
    CF
    PS so far I can open the text files with applescript, that is about the extent of my ability in programing.
    Message was edited by: coldfusions onco

    For a file of that size, you would need to use some shell utilities to get decent performance. To count words, the following script breaks up the text into words, then counts the number of times the specified word is found (a dictionary file is used as an example, so the match is equivalent to 'contains'):
    <pre style="
    font-family: Monaco, 'Courier New', Courier, monospace;
    font-size: 10px;
    font-weight: normal;
    margin: 0px;
    padding: 5px;
    border: 1px solid #000000;
    width: 720px;
    color: #000000;
    background-color: #DAFFB6;
    overflow: auto;"
    title="this text can be pasted into the Script Editor">
    set theFile to "/usr/share/dict/web2" -- a 2.5MB list of words
    set someWords to {¬
    {theWord:"weather", theCount:0}, ¬
    {theWord:"farmers", theCount:0}, ¬
    {theWord:"ploughing", theCount:0}}
    repeat with anItem in someWords
    set aWord to quoted form of theWord of anItem
    try -- break up into individual words, then search and count
    set theCount of anItem to (do shell script "tr -cs '[:alpha:]' " & quoted form of linefeed & " < " & theFile & " | grep -ic " & aWord) as integer
    end try
    end repeat
    someWords
    </pre>
    Is this related to your Automator post?

  • Applescript: Copy File Names into an Email

    *I've been slowly teaching myself Applescript, and can't seem to find a way to do a few things. Basically what I'm trying to do is set up a script that will run when items are dropped into a folder on my FTP. I want the script to have a pop-up dialogue, and generate an email to certain users announcing new files are on the FTP. I have these 2 parts down, but I would also like the body of the email to include a list of the filenames. This part I can't figure out.*
    *I just need to find a function that will copy the filenames of new items, and paste them into the body of the email already being generated. My current code is below. Anyone have any ideas to help me expand?*
    property dialog_timeout : 15 -- set the amount of time before dialogs auto-answer.
    on adding folder items to this_folder after receiving added_items
    try
    tell application "Mail"
    set theMessage to make new outgoing message with properties {visible:true, subject:"New Files on FTP", content:"New files have been posted to incoming folder of the FTP."}
    tell theMessage
    make new to recipient at end of to recipients with properties {name:"Jane Doe", address:"[email protected]"}
    make new to recipient at end of to recipients with properties {name:"John Smith", address:"[email protected]"}
    end tell
    send theMessage
    end tell
    tell application "Finder"
    --get the name of the folder
    set the folder_name to the name of this_folder
    end tell
    -- find out how many new items have been placed in the folder
    set the item_count to the number of items in the added_items
    --create the alert string
    set alert_message to ("Folder Actions Alert:" & return & return) as Unicode text
    if the item_count is greater than 1 then
    set alert_message to alert_message & (the item_count as text) & " new items have "
    else
    set alert_message to alert_message & "One new item has "
    end if
    set alert_message to alert_message & "been placed in folder " & «data utxt201C» & the folder_name & «data utxt201D» & "."
    set the alert_message to (the alert_message & return & return & "Would you like to view the added items?")
    display dialog the alert_message buttons {"Yes", "No"} default button 2 with icon 1 giving up after dialog_timeout
    set the user_choice to the button returned of the result
    if user_choice is "Yes" then
    tell application "Finder"
    --go to the desktop
    activate
    --open the folder
    open this_folder
    --select the items
    reveal the added_items
    end tell
    end if
    end try
    end adding folder items to
    Message was edited by: markeze

    AppleScript forum under OS X Technologies.

Maybe you are looking for

  • How to resolve "Unable to Generate Thumbnail"  error when inserting google calendar as HTML object.

    Using Mac OSX 10.9, Muse 2014.2. Message shows up in Design or preview modes.   I do see the calendar when I view site in browser.  Unfortunately I can't manipulate it at all since all I see is an error message in Design mode. Thanks

  • Can't Log in with regular user & pass

    I am trying to get a question answered. I was always able to access this forum with my usual username and password. Now the forums won't allow me to log in; instead they require that I re-register as a new user under my .Mac address. Though I have do

  • Where could I get the Adobe Reader Mobile 9 SDK?

    I am develop a windows mobile 6.5 application and want to do some tests on viewing PDF file with the mobile. http://www.adobe.com/devnet/readermobile/ I followed as above instruction to mail to [email protected] several times but returned with Mail F

  • HR Time : Requirement of Annual Calendar Report (download on Excel)

    Hello, I would like to know if there is a possibility to download annual calendar of the Planification (PP61 Transaction). At the present time, we can only download one month of the Planification not all the year. Thank you for your help. Malik.

  • Compass app on the ipad

    I might be blind , ignorant , stupid or all three but ... After upgrading my ipad 3 to ios7 I can't find the much celebrated compass. I've always had one so I have no idea whether it's a native app or not. If it's it native will it exist after the up