Very simple example to execute a command in shell and get information.

Very simple example to execute a command in shell and get information.
I have made it little ASOC friendly… :slight_smile:

Command: pip from python.
Args: ex. command awk to print the first string of every paragraph.

You could change the GlobalSearchString to any string without whitespace.
In other words python package names couldn’t include whitespace and thats
why I do not use quoted form…

The search path to pip on your system if you need to change it to test my code.

The output could be single paragraph or multiple it has to do with how python pip works.

property GlobalSearchString : "midi"

set theGlobalSearch to my searchPackagePython:GlobalSearchString args:"awk '{print $1}'"
set theListPackage to its paragraphs of theGlobalSearch
set thePackage to choose from list theListPackage
set thePackageInfo to my infoPackagePython:thePackage
display dialog thePackageInfo

on searchPackagePython:theName args:theArgs
	-- Set searchpath to pip command.
	set theCommand to "/usr/local/bin/pip search" & space
	set thePipe to space & "|"
	set itsArgs to space & theArgs
	return do shell script theCommand & theName & thePipe & itsArgs
end searchPackagePython:args:

on infoPackagePython:theName
	-- Set searchpath to pip command.
	set theCommand to "/usr/local/bin/pip search"
	return do shell script theCommand & space & theName
end infoPackagePython:

This version remove display dialog and include output to TextEdit.
Also included quoted form of GlobalSearchString.

Its possible to have multi strings to search with python pip.

property GlobalSearchString : "midi"

set theGlobalSearchString to quoted form of GlobalSearchString
set theGlobalSearch to my searchPackagePython:theGlobalSearchString args:"awk '{print $1}'"
set theListPackage to its paragraphs of theGlobalSearch
set thePackage to choose from list theListPackage
set thePackageInfo to my infoPackagePython:thePackage
set output to my outputTextDocument:thePackageInfo fontSize:"14"

on outputTextDocument:theInputString fontSize:theFontSize
	tell application "TextEdit"
		activate
		set theDocument to make new document with properties {text:theInputString}
		tell theDocument to set size to theFontSize
		-- Set the bounds of the window
		tell front window to set bounds to {0, 25, 800, 900}
	end tell
end outputTextDocument:fontSize:

on searchPackagePython:theName args:theArgs
	-- Set searchpath to pip command.
	set theCommand to "/usr/local/bin/pip search" & space
	set thePipe to space & "|"
	set itsArgs to space & theArgs
	return do shell script theCommand & theName & thePipe & itsArgs
end searchPackagePython:args:

on infoPackagePython:theName
	-- Set searchpath to pip command.
	set theCommand to "/usr/local/bin/pip search"
	return do shell script theCommand & space & theName
end infoPackagePython: