python - Open text file and search on OS X -



python - Open text file and search on OS X -

i open text file , search string , highlight it.

i use:

command ="open "+'"'+ file +'"' os.system(command)

but want like:

command ="open "+'"'+ file +'"' + "then"+ "ctrl-f(string)"

obviously doesn't work, there way this? want text in string highlighted normal ctrl+f.

you're on right track open; utilize ⌘+f (i'm assuming you're on os x tags), can utilize applescript tell the system events application perform keystroke:

os.system("open " + filename) # may need add together sleep() here if application not open , hence needs time load os.system("""osascript -e 'tell application "system events" keystroke "f" using {command down}'""") os.system("""osascript -e 'tell application "system events" keystroke \"""" + search_term + "\"'")

python osx terminal

Comments

Popular posts from this blog

java - How to set log4j.defaultInitOverride property to false in jboss server 6 -

c - GStreamer 1.0 1.4.5 RTSP Example Server sends 503 Service unavailable -

Using ajax with sonata admin list view pagination -