Use applescript for Python Shell command

Is there a way where I can make applescript to view the output of the python script and also accepts input so that it can pass it to the python script? My script contains several entry so is it possible possible to do? For more than once in entry and exit every time?

You can certainly create handlers AppleScript (functions) that use Python HERE documents, with AppleScript variable passed into Python as command-line arguments, or returned to AppleScript. AppleScript's display of limited capacity, but does not preclude a cocoa of coding, or TCL GUI for the display format most of in the Python code.

You can also write a Python application that can invoke AppleScript, pass the values on the command line values and return to Python AppleScript. This can be done through a presentation of subprocess or directly through NSAppleScript.

Here's an AppleScript that uses a Python Manager to glance in a .docx Word document and display the names of fonts used in it. Only .docx, not. doc. Notes to escape the double quotes and back-slash in the Python script to appease AppleScript.

-wordfonts.applescript

-display fonts (read-only) in the Word (.docx only) document in the menu drop-down

-VikingOSX, 01/2016, support Apple community

-Version 1.2, the additional list comprehension to Python print statement, other settings.

property docx: {'org.openxmlformats.wordprocessingml.document'}

property mydefault: ((path to the documents folder) as text) as alias

Try

the value docxfile to POSIX path of (Choose file type docx default location mydefault without invisible)

If result = {return button: 'Cancel'} then error -128 - cancelled by the user

say application 'System events' to the value docxname to the name of (POSIX file docxfile as alias)

display the dialog box "Document:"& docxfile & return & return & (elements of my docxfonts (quoted form of docxfile)) as text with the title "Word Document Fonts" give up after 20.

we errnbr error error message number

Error_Handler (errnbr, errmsg)

end try

return

on docxfonts (thefile)

return the shell script "python".

import the zip file

import re

Import os

import sys

fonts =]

thedocx = os.path.expanduser(sys.argv[1])

If not thedocx.endswith ('.docx'):

raise exception ("not a valid docx Word document'")

If zipfile.is_zipfile (thedocx):

with the zip file. Zip (thedocx, 'r') as docxzip file:

XMLDATA = docxzip.read('word/fontTable.xml')

fonts = re.findall (r'(?<=w:name=)\"([ \\w+]+)\"="">', xmldata))

print (------"} \".format ('\\n'.comes ([x for x in sorted (fonts) if fonts])) ")

EXPRESSIONS OF FOLKLORE. "

end docxfonts

on error_handler (nbr, msg)

return Display alert «["& nbr &" "']" & msg as critical leave after 10 "»

end error_handler

Python script that illustrates the passage of an argument to an AppleScript application that runs as a subprocess.

#! / usr/bin/env python

# coding: utf-8

# dx.py: illustrates the passage of a Python variable in a function that

# contains a string variable (ascript) which is the AppleScript

# code that osascript runs in the sub-process. The value of allow

# following the scriptname as ARGV 1, which is taken by the

# argv clause of AppleScript.

# Use:. DX.py

# VikingOSX, 12/2015, Apple Support communities

# v1.2

import of subprocesses

Import atexit

import sys

MSG = 'the value of x is 10'.

procs =]

def send_dialog (allow):

AScript = "'

on run argv

Set userCanceled false

If (argv County) = 0 then

Tell application "system events" to display dialog ¬ "argv is 0". "

After 10

on the other

the value of msg (item 1 of argv) text

end if

Try

Tell application "system events" to display dialog ¬ msg

with the title 'Application Communication' give up after 10

the error number - 128

userCanceled set to true

try to end

If userCanceled then return "Cancel".

return

end of race

'''

Try:

proc = subprocess.check_output (['osascript', '-e', ascript, allow])

If "Cancel" in proc.decode('utf-8'): # the user presses the Cancel button

sys. Exit ("User Canceled")

except subprocess. CalledProcessError as e:

print (' Python error: [% d]\n%s\n' % e.returncode, e.output])

generator of # @atexit.register to clean any stray sub-process

def kill_subprocesses():

for proc in procs:

proc. Kill()

def main():

send_dialog (MSG)

If __name__ == "__main__":

sys. Exit (hand ())

Tags: iOS Developer

Similar Questions

  • How can I use applescript for OCR to a bunch of files - with Acrobat XI?

    Hello

    IWant to write an AppleScript (for example) that can be used as a droplet or has a menu to open a folder of pdf files scanned for OCR. And - I want to use Acrobat XI (because it's my version), German version.

    As Acrobat XI is not recordable with applescript editor and I can't find a manual of objects and methods I googled a script that worked with Acrobat 9, but not with Acrobat XI. Here, you define a "Wizard of Action" - Script for example called "OCR this ' and 'click' of the element. But as in Acrobat XI this Item is noch in hand-sbubmenu more than it seems to not work.

    Here is a screenshot:

    Bildschirmfoto 2014-07-14 um 10.57.06.png

    And it's theapplescrpt, tha opens "Aktionsassistent":

    Click on the menu item "Aktionsassistent" in the menu "Tools" from menu item "Tools" in the menu "Anzeige" of the menu bar item "Anzeige" from the menu bar 1

    BotR, so I cannot reach "OCR it."

    If any body has a suspicion - either by clicking on "OCR this ' or sript an OCR on one open our AppleScript, that would be great.

    Thank you

    Smail

    AppleScript is documented in the Acrobat SDK kit. But there is no way to do it.

  • Arguments using Wild-Card in Shell command authorization

    The Shell permission command Set allows the use of wild-card?

    For example, according to command shell permission, what can I put the arguments if I want to enable the command show interface fastethernet 0/1-24 run?

    And also, what should I put in as argument for a ip address if I want to allow "ping x.x.x.x"?

    Thanks in advance.

    Hello

    There are two wildcard characters used under authority of command Shell is the first ' ^ ' sign which designates anything that comes after this is accepted and the second wildcard is ' $' which means anything that is before. In your case, you can use

    Interface FastEthernet 0 1 ^

    and

    Ping ^.

    These commands allow access each Fastethernet and ping to an IP address.

  • Using Applescript for formatting lines in figures

    I have a Numbers spreadsheet where I want to shade the lines according to the (odd) values in my second column (B).

    I've been everywhere in the forum, but I can't seem to find a script that is, and I can't change one and make it work.

    Anyone with a few kind words and a model? :-)

    Hi jsteinaa,

    Here's a method that does not require an Applescript.

    Add another column, C. You can hide this column later.

    Formula in C2 (fill down)

    = IF (ISEVEN (B2) ", B2," "")

    If a value of B is the same, that the cell equal to the B cell c, otherwise insert "" (NULL).

    Conditional highlighting b

    Variation: use the ISODD C function.

    Please call with questions.

    Kind regards

    Ian.

  • AppleScript for recover data from Spotlight

    Here's a challenge for you all...

    Projector in El Capitan can provide much more information, i.e. weather, sports scores and so on. Now, I already have an AppleScript script that allows the user to enter something, and then it will call Spotlight and stick to what they entered. I want to be able to do is read the data Spotlight returned. For example, if the user types in "weather" and Spotlight said she's currently 61 °, I want to be able to transmit the data back in the script. How this could be achieved? If there is no conventional way you know, perhaps via some GUI scripts?

    Thank you.

    Yosemite... no time.  I tried 3 + 2 and saw 5 in the input area.  The following code did not the addition.  We can assume that Apple has some type of skimming preprocessor outside the soluble substance before transmitting the data to the mdfind.

    How do you pass the data to highlight?

    "Things that do not work. (tm) »

    Well, running a unix since applescript command returns data to a variable if you code.

    mdfind-name of pumpkin

    http://osxdaily.com/2006/12/05/use-Spotlight-from-the-command-line-with-mdfind/

    (*
    
    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) & " --- "
    
        set quotedUnix to quoted form of "Pumpkin"
        log "quoted form" & quotedUnix
        try
            set fromUnix to do shell script "mdfind -name " & quotedUnix
            display dialog "mdfind -name " & quotedUnix & return & "returns the following files " & return & fromUnix
        on error errMsg
            log "error..." & errMsg
        end try
    
    end run
    
  • App, opening a file via windows shell commands: "a device attached to the system does not work.

    Hello!

    I hope that someone here will be able to throw some lights on my question, if I post this is the wrong place please let me know because I was directed here (which forum? ). OK, I support and develop custom applications. An older application especially written in Delphi allows users to attached documents (pdf, jpg, txt, etc.) to the records of equipment in a data base. Later users can view these records of equipment and press a button to display the document.

    When the user presses the button to view the document, the application uses the folder variable to save the document to the temporary path and then asks windows via a shell command to open the file. The appeal of Delphi for windows used is the following:

    ShellExecute (GetDesktopWindow, 'open', PChar (TempFile), ",", SW_SHOWNORMAL);

    Normally this process works very well, we have had no problems so far. On a single computer (windows xp pro with Service Pack 3) belonging to a client, instead of opening the file, windows returns the system 31 error and the message ""a device attached to the system is not functioning. ". is displayed.

    * If I navigate to the location where the file is stored on the disk and try to open it, software adobe reader opens the file correctly.

    * I found some suggestions that the file extension is associated properly. PDF associated with Notepad, I changed, and the application could ask windows to open the file very well. Open the file from the location on the work of disc as well. Change the file for adobe and the problem persisted.

    * I reinstalled adobe reader software, but also a previous version of adobe and the problem persisted.

    * The application doesn't have any problem asking other files opened, only those associated with adobe reader on this same machine. The problem does not exist on other machines.

    That about sums up the problem. Any suggestion would be appreciated.

    Thank you

    Louis

    It was determined that the version of adobe reader was at fault.

  • How to activate 'Shell command authorization games '.

    Hello

    I use aaa on Ganymede to check the user to active directory ms.

    I set up a new "Set Shell command authorization" see the attachment for more details.

    But it does not work. So, I just want to check if the use of a command works or not.

    You can see in the file attached, I tried something with the command 'show '.

    But if I connect I am still able to use "view aaa servers" example, but in the 'show' commandbox I asked the agrument "refuse the aaa" inside.

    Why doesn't this work?

    Thanks for the help

    BB

    BB,

    Not sure why you want to do it this way. Trick here is to give all users a priv 15 and then set the permission command, defined according to your need.

    Overlooking priv 15 does not mean that the user will be able to run all the commands. You can set permission set and allow that you want specific orders, the user should be able to run.

    So pls rate this help

    Kind regards

    ~ JG

  • ACS - configure the authorization of shell commands to work under the configuration mode (conf t)

    Hello world

    I'm trying to set up a shell commnds set orders (including t conf mode) will be allowed, with the exception of administrative commands, such as writing, copy, admin, format etc.

    He worked for the commands in privileged mode (most) (such as writing and copy), but did not order t conf mode. It is important to prevent users to perform the ' write for the "and" copy run start "commands, for example.

    Here is the entry in the series of command shell (Partial_access) approval:

    Unmatched orders: permit

    List of commands:

    Admin

    copy

    delete

    do

    format

    To write

    (Relevant) group settings:

    V - shell (exec)

    Privilege level of V - 15

    Shell command authorization set

    Assign permission to command Shell Set to any device network - Partial_access (group name)

    I use CiscoSecure ACS version 4.2 (0)

    Thank you

    Lior

    Hi Lior,

    Please make sure you typed in the AAA client, the following commands: -.

    AAA authorization config-commands

    Thanks for posting your AAA client configuration via "run sh |" I have aaa "and if possible your configuration of privilege"

    HTH

  • Help ACS shell command authorization

    Hello

    I wanted to only allow users to use the command interface. But when I have enabled terminal config of ACS shell command, all commands are allowed. How can I limited users having only permission for command interfaces?

    Thank you

    Two things may be wrong

    (1) you do not have the following command on your AAA Client:

    AAA authorization config-commands

    (2) you have clicked on the 'unmatched orders' = allowed radio option in ACS, take a look on:

    http://www.Cisco.com/en/us/products/sw/secursw/ps2086/products_configuration_example09186a00808d9138.shtml

    Concerning

    Farrukh

  • Some more guideance on the opportunity to use Applescript/JS?

    It is in draft, I want to do:

    1. in InDesign, extract the effective ppI have an image in the 'x' and 'y' directions.

    2. in Photoshop, apply these numbers in some way to the image so that the effective ppi becomes 300 in Indesign. It's a simple formula that you apply to the Resolution of the Image.

    3 then I want to apply a unsharp mask with an edge mask to sharpen the image. There is a number of simple steps.

    I wrote about the whole procedure in Pidgin Applescript (combination of Applescript, BASIC and English) and it works perfectly. I need to do step 1 manually, but for steps 2 and 3, I generated an Action, with a modal command for step 2, who pauses and asks for input.

    I want to know the best way to approach this task. Someone told me (outside of these forums):

    Your best bet will be to post on the forum script. It would need to be Applescript, because I don't think that Javascript can make several applications at the same time.

    However, I'm not positive, but I don't think open as smart object is available in the Photoshop CS3 Applescript dictionary. This may be changed with CS4? Also, when I was working on the use of script with multilayer Photoshop files, he created many seemingly insurmountable problems...

    Michael Hale responded to a previous thread of mine (http://forums.adobe.com/thread/457438) suggesting JS instead of Applescript:

    I would recommend using javascript for several reasons. First of all it is cross-platform, second, there seems to be more people on the forums using JS that ALSO and last but not least in this case you can not work with Action Manager API using ACE. You would have to create and call ACE JS functions

    So, I'm left with: Applescript because it can handle several applications at the same time, but JS because it can manage Actions. What is the best way to approach this task? AS or JS?

    1 extract variables of a selected image in an InDesign document.

    2. open the image in Photoshop and change the resolution of the Image (a calculation is involved)

    3 call my Action to do the rest.

    4. ask if one sharpening more is necessary and the amount. Loop at this stage until the answer is 'no '.

    5. Save and close the image in Photoshop and get back to the selected image in InDesign to see the effect.

    The most popular suggestions.

    1. in InDesign, extract the effective ppI have an image in the 'x' and 'y' directions.

    The effective ppi of an image the ppi of the image as it is presented in ID rather than the real ppi of the image underlying, correct? Just curious...

    2. in Photoshop, apply these numbers in some way to the image so that the effective ppi becomes 300 in Indesign. It's a simple formula that you apply to the + Image resolution +.

    This could be done automatically if you he has scripted instead of calling an action with a modal dialog box.

    What is the best way to approach this task? AS or JS?

    Use both. Run AS to obtain the effective ppi, open the image in PS and change the image of the ground. You, set up a loop (controlled with a ' sharpening more?) ("guest) who calls your action via JS (app.doAction ("actionName","actionSetName"). Have, save and close the image, and then will return to ID to see the results.

    You can do all this in JS, but the solution would be certainly more complex, especially because you would have to use BridgeTalk to send messages back and forth between ID and Psalm

    X

  • Use AppleScript to open boxes smart mailboxes

    Is it possible to use AppleScript to open/view a specific smart mailbox in mail?

    I have a Microsoft Exchange e-mail account in Mail, with several boxes to letters and emails stored in each. The name of each mailbox corresponds to a name of a certain record/entry in a FileMaker Pro 13 database. I would like to have a button in every record/entry in the FileMaker database, once clicked to run an AppleScript script which will be open / view of the mailbox in mail for that particular record.

    For reference, I'm under FileMaker Pro 13, Mail (v9.3) on OS X El Capitan (v10.11.4).

    Is it possible to use AppleScript to open/view a specific smart mailbox in mail?

    I don't know anything about Microsoft Exchange or FileMaker Pro.

    However, the following GUI script may select a smart mailbox under OS X 10.11.3.

    the value theSmartMailboxName to 'TEST' - replace 'TEST' with any name of your choice

    say application "Mail".

    launch

    activate

    say application 'System events' to say process "Mail".

    key sequence '0' using {control down}

    If subrole of window 1 is "AXFloatingWindow" then click on the button 1 of window 1

    if not (are scrolling area 1 of the Group splitter 1 of window 1) then

    key sequence "m" using { control down,shift down}

    end if

    say 1 1 of the Group splitter 1 in structure window scrolling area 1

    Select (row 1 of which value of text field 1 of UI element 1 is theSmartMailboxName)

    end say

    end say

    end say


    Also take a look at this article.

  • Want to know how to find the alias to a random file using applescript

    Hi, I was wondering if I can find the alias for any file that I even clicked on using applescript.

    I searched online, and there is not much that I can take some.

    So, for example in applescript I "put fileToFind to alias (...)" but this alias depends entirely on the single user, click on the file. So I do not know this alias exactly, is there a way that I can put this variable "fileToFind" to an appropriate alias of the file I even clicked on?

    single click

    Info (CMD + i)

  • Path of the most recent added file using applescript

    I use appleScript Automator to download new pictures on my Instagram.

    The script trigger when the new file is added to a folder "updates".

    Open the app (work)

    activate an application "Uploader HD for Instagram"

    delay 0.5

    Tell application "system events".

    say "Uploader HD for Instagram" processes

    Click on the menu "open...". "the menu 1 menu bar item 'File' from the menu bar 1

    tell the end

    tell the end

    Activate the "go in the folder" CMD + SHIFT + G

    Tell application "system events".

    delay 1

    combination of keys 'G' using {control down, moving down}

    delay 1

    tell the end

    This is the problem... I "Don't KNOW" the name of the most recent added the file and there are a lot of files on the folder... So I can't use the full path of the file on the 'go in the folder ".

    Tell application "system events".

    combination of keys "/ Users/HazaelDiaz/Google Drive/IFTTT/Instagram/update/2016 / '.

    delay of 0.1

    strike back

    delay of 0.1

    strike back

    tell the end

    Since I trigger the 'applescrip' using the 'Workflow folder action... " Is it possible that I can get the value or the path of the new file included?

    I found a code that renames all the files from 0 to xxx folder action, but the new included file is always the last of them on digital process... is possible to rename the files and give the new file name "update1.jpg" first?

    Also I can order "Go to folder" action must seek that specify the file: 'update1.jpg. '

    This is the script name change: (BTW, these scripts always ask me to select folder... and what I want is to be automated out of my interaction with but do not know how to change so it will always use the "updates" folder

    Tell application "Finder".

    a in each file of the entire contents of the value (choose the folder)

    Repeat with aa in one

    the file_name my MakeBase (aa AsString) value

    If file_name is not 'JUMP' then

    count_er Set 1

    the value all_files (all files in aa)

    Repeat the operation with ff in all_files

    the name value of ff ((texte-3-1 par le biais de ("000" & (count_er as string))) & "." & (name extension for ff))

    Set count_er to count_er + 1

    end repeat

    end if

    end repeat

    tell the end

    to MakeBase (txt)

    the value astid delimiters to point to the text of the AppleScript

    the text value of the point AppleScript delimiters «:»

    the value for each item of text txt new_Name_Raw

    the text value of point AppleScript delimiters to "_".

    the value final_Name for each item in new_Name_Raw text text

    the text value of the point AppleScript astid delimiters

    If length > 251 of final_Name then set final_Name on 'SKIP' - will be more than 4 characters for counter

    return final_Name

    end MakeBase

    Any help will be much appreciated.

    Thanks /.

    What version of Mac OS X are you running?

  • Everytime I turn on my Mac Java says he needs to install the message says "to use the line tool java command, you must install a JDK.  Click on "more information visit the java developer kit download site."  I followed all these steps and downloSoftware.

    The message says "to use the line tool java command, you must install a JDK.  Click on "more information visit the java developer kit download site."  I followed all these steps and downloaded the correct software update, but still getting the message.

    A

    If you have installed the plugin of Facebook video appeal and you no longer want to use it, you can remove it as follows.

    1 back up all data.

    2. open the library folder in your home folder by holding down the option key and selecting

    Go ▹ library

    in the Finder menu bar.

    3. place these items in the library folder to the Trash:

    LaunchAgents/com.facebook.videochat.name.plist

    Support/Facebook app

    Here the name represents the name of your Facebook.

    4 log off or restart the computer, and then empty the trash.

    B

    If you do not use this plugin, or any other software (for example, some Adobe products), which depends on Java, install the Java runtime distributed by Apple.

    C

    If you do not have the Facebook plugin and you don't want to install Java, please ask for further instructions.

  • Using powershell in the RACADM command variables

    I have a powershell script that I use to look through a CSV file to assign a static iDRAC IP based on the serial number.

    Here's a command that works very well!

    racadm - r $oldIP - u root Pei calvin set iDRAC.IPv4.Gateway $gw

    the $oldIP and the $gw are the variables that have been assigned values previously in my script.

    I can check with 'get iDRAC.IPv4' and all it's thanks to the gateway.

    I attribute the $gw of the exact same way that I attribute to the variable $newIP.

    Here is the command that does not work with the PowerShell variable:

    racadm - r $oldIP - u root Pei calvin set iDRAC.IPv4.Address $newIP

    Returns: "Error: RAC947: invalid object specified value.»

    If I use exactly the same command (by pressing the arrow upward for the previous command) and replace $newIP with the actual IP address, it works fine... If I wanted to manually enter each IP... which I did not.

    I can verify that $newIP is in fact I need by calling just separately.  Seems good.  It "SHOULD" work.  Especially if $gw works very well.

    I tried every way Wednesday to make it work.  Rearrange things in the code.  Made sure that iDRAC.IPv4.DHCPEnable 0 and iDRAC.IPv4 allow 1 are defined.  Research for hours trying to find an explanation or a reason for the failure.  Could not find anything.

    Can the iDRAC.IPv4.Address command not to take anything except an IP address that is actually typed in?  A kind of validation?

    Does anyone have any ideas as to why it doesn't work?

    RACADM version 8.1.0 build 1518 (Yes... I looked into that too).

    Use the basic example functions. Write-Host $oldIP to check what is happening in reality not in these variables.

Maybe you are looking for