Wednesday, January 17, 2018

#1 2013-04-04 01:40:59 am

McUsrII
Member
Registered: 2012-11-21
Posts: 3046
Website

Miscellanous scripts

Hello.

This is a script that helps you locate and view a C-header file, the syntax is gheader stdio, and not gheader stdio.h, it is meant to work with Apple's headers, the standard C-library, and what libraries you have downloaded via Macports. (/opt/local/include). You'll get the hang of how to modify it, should you need it.

The shell script, should easily be incorporated into an applescript, and leverages upon the searchpaths I have (you specify ) specified. Also the fact that the include file with the shortest path is the most correct one. So if you need a different searchpath, then you'll have to add some if clauses. It is also quite silent if you execute it from an applescript, only echoing the path of the header file if you are in a terminal window.

[code]#!/bin/bash
# http://macscripter.net/viewtopic.php?pid=162319#p162319
# © 2013 McUsr and put in public domain you may not post this elsewhere.
if [ $# -eq 0 ]; then
    if test -t 0 ; then
        echo "gheader: You need to supply a name that resembles a header file as a parameter." >/dev/tty
    fi
    exit 1;
fi
toopen=0
if [ $1 = -o ] ; then
    toopen=1
    shift
fi
if [ $# -eq 0 ]; then
    if test -t 0 ; then
        echo "gheader: You need to supply a name that resembles a header file as a parameter." >/dev/tty
    fi
    exit 1;
fi
header=${1%%.h}.h
a=$(locate $header |grep "^/System/Library/.*/$header" |awk '{ print length $1 }' |sort |sed -n  '1s/\([[:digit:][[:digit:]]*\)\([^[:digit:]][^[:digit:]]*\)/\2/p')
if test -z $a ; then
    a=$(locate $1 |grep "^/usr/include/.*/*$header" |awk '{ print length $1 }' |sort |sed -n  '1s/\([[:digit:][[:digit:]]*\)\([^[:digit:]][^[:digit:]]*\)/\2/p')
    if test -z $a ; then
        a=$(locate $1 |grep "^/opt/local/include/.*/*$header" |awk '{ print length $1 }' |sort |sed -n  '1s/\([[:digit:][[:digit:]]*\)\([^[:digit:]][^[:digit:]]*\)/\2/p')
        if test -z $a ; then
            if test -t 0 ; then
                echo "gheader: Couldn't locate $header" >/dev/tty
            fi
            exit 1
        fi
    fi
fi
if test -t 0 ; then
    echo $a >/dev/tty
fi
if [ $toopen -eq 0 ]; then
    qlmanage -px $a  2>&1 >/dev/null &
else
    open $a &
fi
exit 0[/code]

Last edited by McUsrII (2013-04-16 08:08:41 am)


Filed under: coding-tool

Offline

 

#2 2013-04-06 05:01:23 am

McUsrII
Member
Registered: 2012-11-21
Posts: 3046
Website

Re: Miscellanous scripts

Hello.

I have evolved the script in post #1 to be agnostic to whether you supplied a .h extension or not.

Last edited by McUsrII (2013-04-06 05:02:56 am)


Filed under: gheader

Offline

 

#3 2013-04-06 07:51:37 am

McUsrII
Member
Registered: 2012-11-21
Posts: 3046
Website

Re: Miscellanous scripts

Hello.

I have changed the script in post #1 to provide a better form of agnosticisim. wink

Trouble was, with the previous scheme, that .so files and what not, ended up  with an icon in quicklook, so I have inverted it all, looking strictly for header files, and adding any missing .h suffixes for starters instead of ignoring them during the lookups.

Last edited by McUsrII (2013-04-06 07:54:36 am)


Filed under: coding-tool

Offline

 

#4 2013-04-16 07:22:22 am

McUsrII
Member
Registered: 2012-11-21
Posts: 3046
Website

Re: Miscellanous scripts

Hello.

I have updated the script in post #1, to be sure that the latest version is there, I have renamed it to ghead for brevity.

I call it with the script below, to have the header files I want to have a peek at handy, from a history list. This concept isn't fully evolved yet, one day I care, and have the time, I'll synchronize this history with some other scripts I use from Safari, Preview and XCode, to have one common history list file.

Applescript:

-- [url]http://macscripter.net/viewtopic.php?pid=162319#p162319[/url]
-- © McUsr and put in public domain you may not post this elsewhere.


property headerFile : ""
property histList : {"No Header files entered."}
global executableIcon
on run
   local fromclip, thNm
   set {fromclip, thNm} to {false, ""}
   tell application id "sevs"
       if UI elements enabled is not true then
           set UI elements enabled to true
       end if
       set thNm to name of item 1 of (every application process whose visible is true and frontmost is true)
   end tell
   tell application thNm to activate
   if thNm is in {"TextWrangler", "BBEdit", "XCode", "Preview", "Safari", "TextEdit"} then
       set theSpare to the clipboard as record
       set the clipboard to ""
       tell application thNm to activate
       if thNm is not "Safari" then
           tell application id "sevs" to keystroke "c" using command down
           set extraction to the clipboard as text
       else
           tell application "Safari"
               activate
               do JavaScript "self.focus()"
               set extraction to (do JavaScript "\"\"+window.getSelection();" in its document 1)
               if extraction = "" then
                   tell application id "sevs" to keystroke "c" using command down
                   set extraction to the clipboard
               end if
           end tell
       end if
       set the clipboard to theSpare as record
       if extraction ≠ "" then
           set headerFile to extraction
           set fromclip to true
       end if
   else
       tell application thNm to activate
   end if
   
   if not fromclip then
       set executableIcon to a reference to file ((path to library folder from system domain as text) & "CoreServices:CoreTypes.bundle:Contents:Resources:ExecutableBinaryIcon.icns")
       try
           tell application "SystemUIServer"
               activate
               
               set {headerFile, tbutton} to {text returned, button returned} of (display dialog "Enter Header file" with title "Header Files" default answer headerFile buttons {"History", "Cancel", "Ok"} default button 3 with icon executableIcon)
           end tell
       on error e number n
           tell application thNm to activate
           tell application id "sevs"
               click window 1 of application process thNm
           end tell
           error number -128
       end try
       tell application thNm to activate
       if tbutton = "History" then
           tell application "SystemUIServer"
               activate
               set headerFileFromList to choose from list histList default items item 1 of histList with title "Header Files"
           end tell
           if headerFileFromList = false then
               tell application "SystemUIServer"
                   activate
                   try
                       display dialog "Do you want to enter one after all?" with title "Header Files" with icon executableIcon
                       set headerFile to text returned of (display dialog "Enter Header file" with title "Header Files" default answer headerFile with icon executableIcon)
                   on error e number nu
                       tell application thNm to activate
                       tell application id "sevs"
                           click window 1 of application process thNm
                       end tell
                       error number -128
                   end try
               end tell
           else
               set headerFile to headerFileFromList as text
               if headerFile = "No Header files entered." then
                   tell application thNm to activate
                   tell application id "sevs"
                       click window 1 of application process thNm
                   end tell
                   error number -128
               end if
           end if
       end if
   end if
   set res to (do shell script "ghead " & headerFile & " 2>&1 >/dev/null ; test $? -eq 0 && echo \"true\" || echo \"false\"") as boolean
   if res = true then
       if "No Header files entered." is in histList then
           set histList to rest of histList
       end if
       if headerFile is not in histList then
           set end of histList to headerFile
       end if
   end if
   tell me to quit
end run

Last edited by McUsrII (2013-04-16 02:49:28 pm)


Filed under: coding-tool

Offline

 

#5 2013-04-16 11:17:47 am

McUsrII
Member
Registered: 2012-11-21
Posts: 3046
Website

Re: Miscellanous scripts

Hello.

I thought: "why not coalesce all the scripts into one, then I don't have to write handlers for writing the history for  each and every script that uses ghead in post #1". The script in the post above, is a "one size fits all", that is to be used from every app, with and without a selection. You have to see to that nothing is selected in order to get the dialog box, but it respects the previous contents of the clip board.

I have also fixed an issue whith Safari, when it gets to be obnoxious, and don't let me copy the selection of the front window.

Last edited by McUsrII (2013-04-16 11:18:41 am)


Filed under: coding-tool

Offline

 

#6 2013-04-16 01:41:01 pm

McUsrII
Member
Registered: 2012-11-21
Posts: 3046
Website

Re: Miscellanous scripts

Hello.

I saved it as an applet, with the name ghead, and set LSUIElements to 1 in its plist file to make it work from spotlight, and quicksilver flawlessly as well.

In the script menu the  "script" looks like this smile

Applescript:

tell application "ghead" to run

Last edited by McUsrII (2013-04-16 01:41:20 pm)


Filed under: coding-tools

Offline

 

#7 2013-04-16 02:24:43 pm

McUsrII
Member
Registered: 2012-11-21
Posts: 3046
Website

Re: Miscellanous scripts

Hello.

I have packed the shell script into the applet, that can be downloaded from here.

Enjoy!


Filed under: coding-tool

Offline

 

#8 2013-04-17 04:30:19 am

McUsrII
Member
Registered: 2012-11-21
Posts: 3046
Website

Re: Miscellanous scripts

Hello.

I finally figured out how to use the app from an Automator Service as painlessly as possible.

First I open Automater, and makes a new service, that shall process marked text.

Secondly I add an exececute shell script action which should get the content below.

[code] open -a "ghead"[/code]
Save it, as GetHeader for instance, and you are good to go open header files from the services menuitem of the contextual menu. smile


Filed under: coding-tool

Offline

 

#9 2013-04-17 05:00:40 am

McUsrII
Member
Registered: 2012-11-21
Posts: 3046
Website

Re: Miscellanous scripts

Hello.

I am very picky about windows retaining their focus, after an app, or a script has been run.

Well, now this is script should be fixed, as far as I know, I use UI scripting to make it happen  like this:


Applescript:


tell application thNm to activate
   tell application id "sevs"
       click window 1 of application process thNm
   end tell
   error number -128
end tell

The app in the link. is updated.

Last edited by McUsrII (2013-04-17 05:02:58 am)


Filed under: coding-tool

Offline

 

#10 2013-04-17 05:16:16 am

McUsrII
Member
Registered: 2012-11-21
Posts: 3046
Website

Re: Miscellanous scripts

Hello.

I made a little change while I were at it:

Now it will ask you, if it couldn't find any header file the first time around (misspelling).

It can still be found here.

And as far as I know, I am done with it. I won't write help file for this, so the basic idea is to mark or input the name of a  header file, say stdio.h, or CFSet.h or something, and it will pop up in quicklook right in front of you. If XCode is still the default editor for c and h files, then the header file will pop up into XCode if you double click on it. smile

Last edited by McUsrII (2013-04-17 05:16:53 am)


Filed under: coding-tool

Offline

 

#11 2013-04-17 08:28:48 pm

McUsrII
Member
Registered: 2012-11-21
Posts: 3046
Website

Re: Miscellanous scripts

Hello.

I must say I am fairly happy with the applet for displaying header files, so I thought I'd wrap the gman script: A shell script for using quicklook to display manual pages into the same kind of applet. Here it is

You make a service for it to execute the applet from the contextual menu the same way as described in post #8.

If the manual page looks like it is html formatted, then chances are big that the manual page will pop up in Safari or your default web-browser, should you double click on it in quicklook.

Enjoy

Last edited by McUsrII (2013-04-17 08:32:17 pm)


Filed under: coding-tool

Offline

 

#12 2013-04-18 12:55:58 pm

McUsrII
Member
Registered: 2012-11-21
Posts: 3046
Website

Re: Miscellanous scripts

Hello.


I fixed a bug in ghead.app, concering having marked something that doesn't go for a header file.

The new version can be found It can still be found here.

I'll most probably have to do the same fix in gman.app as well.


Filed under: coding-tool

Offline

 

#13 2013-04-19 04:10:27 am

McUsrII
Member
Registered: 2012-11-21
Posts: 3046
Website

Re: Miscellanous scripts

Hello.

I have done something more to the logic of ghead, so that it won't be baffled by a selection in your active window, that doesn't return a result.

I have also tried to speed it a little bit up, but I realize I have to write the history to disk, to get it to be more responsive, and it isn't that bad really. But who knows, those computer seconds do take a long long time. smile

PS. People who use this are also supposed to have activity monitor open. smile But now it dies after 2 minutes of inactivity, should the dialog of the faceless app disappear, without you being inclined to hide the frontmost apps to find it.

Due to the changes I have made, I don't think that to be an issue anymore anyway.


Filed under: coding-tool

Offline

 

#14 2013-05-31 03:00:39 am

McUsrII
Member
Registered: 2012-11-21
Posts: 3046
Website

Re: Miscellanous scripts

Hello.

A little script that shows the folders of a directory tree that contains scpt, applescript or scpt files, in a TextEdit window, then it asks you, and lets you open one of the folders if you want to.

It doesn't play well with filenames that contains "…" (ellipsis) and such.

If you have your script folders in just one place, it would be practical, to subsitute a hard path, for the choose folder dialog it starts with.

Applescript:

-- Copyright 2013 © McUsr and put into public domain

set toolbarUtilitiesIcon to a reference to file ((path to library folder from system domain as text) & "CoreServices:CoreTypes.bundle:Contents:Resources:ToolbarUtilitiesFolderIcon.icns") as alias
set pxpath to POSIX path of (choose folder)
set theDirs to do shell script "rootFol=" & quoted form of pxpath & " ;cd $rootFol; ( echo \"ScriptFolders in \"$rootFol ; echo \"=============================================================
\" ;mdfind -onlyin . \"kMDItemFSName == '*.scpt' || kMDItemFSName ='*.scptd'|| kMDItemFSName ='*.applescript' \" | /usr/bin/sed -n 's_'\"$rootFol\"'\\(..*[/]\\)\\([^/][^/]*\\)$_./\\1_p' | awk '{ dir[$0]=$0 } END { for (a in dir ) print a }' |sort )"


tell application "TextEdit"
   make new document
   set text of document 1 to theDirs
end tell
tell application "TextEdit" to activate

try
   tell application "SystemUIServer"
       activate
       display dialog "Would you like to open a folder?" with title "Script Folder Lister" buttons {"Cancel", "Yes"} default button 2 with icon toolbarUtilitiesIcon
   end tell
on error
   tell application "TextEdit" to activate
   error number -128
end try

set theDirList to paragraphs of (do shell script "rootFol=" & quoted form of pxpath & " ; tr -s '
' '
' <<<"
& quoted form of theDirs & " | /usr/bin/sed -n '1,3 ! s_\\./\\(.*\\)_'\"$rootFol\"'\\1_p'")

tell application "SystemUIServer"
   activate
   set toOpen to (choose from list theDirList default items item 1 of theDirList with prompt "Choose a ScriptFolder to Open." with title "Script Folder Lister")
end tell
if toOpen is not false then
   do shell script "open " & quoted form of (toOpen as text)
   tell application "Finder" to activate
else
   tell application "TextEdit" to activate
end if

Last edited by McUsrII (2013-05-31 03:25:37 pm)

Offline

 

#15 2013-05-31 03:37:40 am

McUsrII
Member
Registered: 2012-11-21
Posts: 3046
Website

Re: Miscellanous scripts

Hello.

This is the version for c and m files, do you need M then add : " || kMDItem == '*.H' " to the mditem clause, and similarily for cpp.

Applescript:

-- Copyright 2013 © McUsr and put into public domain
property scriptTitle : "C-Source files"
set toolbarUtilitiesIcon to a reference to file ((path to library folder from system domain as text) & "CoreServices:CoreTypes.bundle:Contents:Resources:ToolbarUtilitiesFolderIcon.icns") as alias
set pxPath to POSIX path of (choose folder)
set theDirs to do shell script "rootFol=" & quoted form of pxPath & " ;cd $rootFol; ( echo \"" & scriptTitle & " in \"$rootFol ; echo \"=============================================================
\" ;mdfind -onlyin . \"kMDItemFSName == '*.c' || kMDItemFSName ='*.m' \" | /usr/bin/sed -n 's_'\"$rootFol\"'\\(..*[/]\\)\\([^/][^/]*\\)$_./\\1_p' | awk '{ dir[$0]=$0 } END { for (a in dir ) print a }' |sort )"


tell application "TextEdit"
   make new document
   set text of document 1 to theDirs
end tell
tell application "TextEdit" to activate

try
   tell application "SystemUIServer"
       activate
       display dialog "Would you like to open a folder?" with title scriptTitle & " from " & pxPath buttons {"Cancel", "Yes"} default button 2 with icon toolbarUtilitiesIcon
   end tell
on error
   tell application "TextEdit" to activate
   error number -128
end try

set theDirList to paragraphs of (do shell script "rootFol=" & quoted form of pxPath & " ; tr -s '
' '
' <<<"
& quoted form of theDirs & " | /usr/bin/sed -n '1,3 ! s_\\./\\(.*\\)_'\"$rootFol\"'\\1_p'")

tell application "SystemUIServer"
   activate
   set toOpen to (choose from list theDirList default items item 1 of theDirList with prompt "Choose a ScriptFolder to Open." with title scriptTitle & " from " & pxPath)
end tell
if toOpen is not false then
   do shell script "open " & quoted form of (toOpen as text)
   tell application "Finder" to activate
else
   tell application "TextEdit" to activate
end if

Last edited by McUsrII (2013-05-31 03:27:09 pm)

Offline

 

#16 2013-05-31 03:54:40 am

McUsrII
Member
Registered: 2012-11-21
Posts: 3046
Website

Re: Miscellanous scripts

While I am at it:

Here is one, you'll like if you need to look at your own header files from within XCode, you just change the property revalInTextEdit to false, if you think an open dialog will suffice. You just change the script to use a posix path, if you have your stuff in one place, and customize it further, if you want to get at your locall library source files.

Applescript:

-- Copyright 2013 © McUsr and put into public domain
property revalInTextEdit : false
property scriptTitle : "Private Header Files"
set pxpath to POSIX path of (choose folder)
set toolbarUtilitiesIcon to a reference to file ((path to library folder from system domain as text) & "CoreServices:CoreTypes.bundle:Contents:Resources:ToolbarUtilitiesFolderIcon.icns") as alias
set pxPath to "~/include"
set theDirs to do shell script "rootFol=" & pxPath & " ; cd $rootFol; ( echo \"" & scriptTitle & "s in: \"$rootFol ; echo \"=============================================================
\" ;mdfind -onlyin . \"kMDItemFSName == '*.h    '\" |sort )"


if revalInTextEdit then
   tell application "TextEdit"
       make new document
       set text of document 1 to theDirs
   end tell
   tell application "TextEdit" to activate
   
   try
       tell application "SystemUIServer"
           activate
           display dialog "Would you like to open a " & scriptTitle & " from " & pxPath & "?" with title my scriptTitle & " from " & pxPath buttons {"Cancel", "Yes"} default button 2 with icon toolbarUtilitiesIcon
       end tell
   on error
       tell application "TextEdit" to activate
       error number -128
   end try
end if
set theDirList to paragraphs of (do shell script "tr -s '
' '
' <<<"
& quoted form of theDirs)

tell application "SystemUIServer"
   activate
   set toOpen to (choose from list theDirList default items item 1 of theDirList with prompt "Choose the " & scriptTitle & " from " & pxPath & " to open." with title my scriptTitle & " from " & pxPath)
end tell
if toOpen is not false then
   do shell script "open " & quoted form of (toOpen as text)
   tell application "Xcode" to activate
else
   if revalInTextEdit then
       tell application "TextEdit" to activate
   else
       local nm
       tell application "System Events" to set nm to (get name of first application process whose visible is true and frontmost is true)
       tell application nm to activate
   end if
end if

Last edited by McUsrII (2013-05-31 03:16:33 pm)

Offline

 

#17 2013-05-31 07:06:00 am

McUsrII
Member
Registered: 2012-11-21
Posts: 3046
Website

Re: Miscellanous scripts

I am still at it, here is one that lets you search for headerfiles, containing an identifer by a regex.

In /System/Library/Frameworks

Applescript:

-- Copyright 2013 © McUsr and put into public domain
property revalInTextEdit : false
property searchWord : ""
property scriptTitle : "/System/Library/Frameworks"
set toolbarUtilitiesIcon to a reference to file ((path to library folder from system domain as text) & "CoreServices:CoreTypes.bundle:Contents:Resources:ToolbarUtilitiesFolderIcon.icns") as alias
local nm
tell application (path to frontmost application as text)
   set searchWord to text returned of (display dialog "Enter a search term, Miniminum one letter. Wildcards where you like them!" with title my scriptTitle default answer searchWord with icon toolbarUtilitiesIcon)
end tell
if searchWord = "" then
   tell application "System Events" to set nm to (get name of first application process whose visible is true and frontmost is true)
   tell application nm to activate
   error number -128
   
end if


set theFiles to do shell script "( echo \"" & scriptTitle & " Header files containing: \"\"" & searchWord & "\" ; echo \"=============================================================
\" ; mdfind -0 -onlyin "
& scriptTitle & " \"kMDItemFSName == '*.h'\" |xargs -0 -I {} grep -l " & "\"" & searchWord & "\"" & " {} ); true "

if revalInTextEdit then
   tell application "TextEdit"
       make new document
       set text of document 1 to theFiles
   end tell
   tell application "TextEdit" to activate
   
   try
       tell application "SystemUIServer"
           activate
           display dialog "Would you like to open an include file?" with title "Include files in " & my scriptTitle buttons {"Cancel", "Yes"} default button 2 with icon toolbarUtilitiesIcon
       end tell
   on error
       tell application "TextEdit" to activate
       error number -128
   end try
end if
set theFilesList to paragraphs of (do shell script "tr -s '
' '
' <<<"
& quoted form of theFiles)

tell application "SystemUIServer"
   activate
   set toOpen to (choose from list theFilesList default items item 1 of theFilesList with prompt "Choose the Include file to Open." with title "Include files in " & scriptTitle)
end tell
if toOpen is not false then
   do shell script "open " & quoted form of (toOpen as text)
   tell application "Xcode" to activate
else
   if revalInTextEdit then
       tell application "TextEdit" to activate
   else
       tell application "System Events" to set nm to (get name of first application process whose visible is true and frontmost is true)
       tell application nm to activate
   end if
end if

You can just change the property scriptTitle to point to a different include path, and save the script under another name.

Last edited by McUsrII (2013-05-31 02:57:50 pm)


Filed under: HeaderFiles

Offline

 

#18 2013-05-31 02:19:11 pm

McUsrII
Member
Registered: 2012-11-21
Posts: 3046
Website

Re: Miscellanous scripts

Hello.

I have improved the three scripts in post #17 slightly with regards to search criteria, so that no double ticks, ment to escape the regexp are showing up in the dialog again.

Offline

 

#19 2013-05-31 03:30:58 pm

McUsrII
Member
Registered: 2012-11-21
Posts: 3046
Website

Re: Miscellanous scripts

Hello.

I have updated the scripts in post #14,#15#16 and #17 Mostly with regard to layout, and made it easy to duplicate the script in post #17 to suit your own  needs for  other dedicated paths, as you usually know which framework, your are looking for an identifier in. (That is why I haven't made it into one slough with a choose from list for picking framework.

Last edited by McUsrII (2013-05-31 03:31:20 pm)

Offline

 

#20 2013-06-02 02:00:22 am

McUsrII
Member
Registered: 2012-11-21
Posts: 3046
Website

Re: Miscellanous scripts

Hello.

I grabbed DJ Bazzie Wazzies script for using StefanK's SKProgressbar in post #6 and modified it slightly, as I had to wait for getting the results, when searching for indentifiers.

StefanK's SKProgress bar can be found here

I used this to modify the script in post #17 this thread, and the modded version is below.

I am pleased with the result! Enjoy! wink

Applescript:

-- Copyright 2013 © McUsr and put into public domain
-- StefanK's SKProgressBar: © StefanK and not in public domain for commercial purposes! [url]http://macscripter.net/viewtopic.php?pid=160302#p160302[/url]
-- DJ Bazzie Wazzie © DJ Bazzie Wazzie SKProgressBar code [url]http://macscripter.net/viewtopic.php?id=40763[/url]
property revalInTextEdit : false
property searchWord : ""
property scriptTitle : "/usr/include"
set toolbarUtilitiesIcon to a reference to file ((path to library folder from system domain as text) & "CoreServices:CoreTypes.bundle:Contents:Resources:ToolbarUtilitiesFolderIcon.icns") as alias
local nm
tell application (path to frontmost application as text)
   set searchWord to text returned of (display dialog "Enter a search term, Miniminum one letter. Wildcards where you like them!" with title my scriptTitle default answer searchWord with icon toolbarUtilitiesIcon)
end tell
if searchWord = "" then
   tell application "System Events" to set nm to (get name of first application process whose visible is true and frontmost is true)
   tell application nm to activate
   error number -128
   
end if
tell application "SKProgressBar"
   set floating to true
   set position to {600, 550}
   set width to 500.0
   set title to "Include files in " & scriptTitle
   set header to "Searching.."
   set header alignment to left
   set footer to "For identifers"
   set footer alignment to right
   set show window to true
   tell progress bar
       activate
       set indeterminate to true
       start animation
   end tell
end tell

set theFiles to do shell script "( echo \"" & scriptTitle & " Header files containing: \"\"" & searchWord & "\" ; echo \"=============================================================
\" ; mdfind -0 -onlyin "
& scriptTitle & " \"kMDItemFSName == '*.h'\" |xargs -0 -I {} grep -l " & "\"" & searchWord & "\"" & " {} ); true "
tell application "SKProgressBar"
   stop animation
   set show window to false
   quit
end tell

if revalInTextEdit then
   tell application "TextEdit"
       make new document
       set text of document 1 to theFiles
   end tell
   tell application "TextEdit" to activate
   
   try
       tell application "SystemUIServer"
           activate
           display dialog "Would you like to open an include file?" with title "Include files in " & scriptTitle buttons {"Cancel", "Yes"} default button 2 with icon toolbarUtilitiesIcon
       end tell
   on error
       tell application "TextEdit" to activate
       error number -128
   end try
end if
set theFilesList to paragraphs of (do shell script "tr -s '
' '
' <<<"
& quoted form of theFiles)

tell application "SystemUIServer"
   activate
   set toOpen to (choose from list theFilesList default items item 1 of theFilesList with prompt "Choose the Include file to Open." with title "Include files in " & scriptTitle)
end tell
if toOpen is not false then
   do shell script "open " & quoted form of (toOpen as text)
   tell application "Xcode" to activate
else
   if revalInTextEdit then
       tell application "TextEdit" to activate
   else
       tell application "System Events" to set nm to (get name of first application process whose visible is true and frontmost is true)
       tell application nm to activate
   end if
end if


Last edited by McUsrII (2013-06-02 02:21:16 am)


Filed under: SKProgressBar

Offline

 

#21 2013-06-25 04:46:08 pm

McUsrII
Member
Registered: 2012-11-21
Posts: 3046
Website

Re: Miscellanous scripts

Hello

For those of you fortunate enough to have such a new version of OS X that your Library aren't indexed by spotlight anymore, please do try this:

Applescript:

do shell script " mdimport ~/Library"

I have gotten that line from Technical Q&A QA1475: Tips for searching Headers, APIs and ADC reference material.

But it should work equally well for stuff stored in the Library folder. smile

The Document just mentioned, puts the scripts in the posts above in a whole new light, making them less necessary, once you have read and adapted to the Q&A, but there should still be some use for them.

Here is a script for importing the headerr file for you for good measure (from 1475), I believe that you from Snow Leopard onwards then can write  name: stdio.h for instance, in the Spotligt bar. wink

Applescript:

do shell script "mdimport /usr/include
mdimport /usr/local/include
mdimport /System/Library/Frameworks"

And while I am at it, here are two snippets for turning Airport on and off:

Applescript:

do shell script "networksetup -setairportpower en1 on"

I knew you'd guess it but:

Applescript:

do shell script "networksetup -setairportpower en1 off"

smile

Last edited by McUsrII (2013-06-25 05:39:27 pm)

Offline

 

#22 2013-12-08 03:54:14 am

McUsrII
Member
Registered: 2012-11-21
Posts: 3046
Website

Re: Miscellanous scripts

Hello.

Here are some links to some quicklook plugins that makes the script above work as they used to before Mavericks.

sindresorhus/quick-look-plugins

QuickLook Plugins List

There is is also an AppleScript Quick look plugin out there that works, as an aside. The one I use is named ScriptQL.qlgenerator

The path to the header files are now changed to:

/Applications/Xcode.app/
Contents/Developer/Platforms/MacOSX.platform/
Developer/SDKs/MacOSX10.9.sdk


(Thanks to  Shane Stanley.)

This is for the mdimport you'll probably have to do manually by the commands in the post right above.

Last edited by McUsrII (2013-12-08 03:56:35 am)

Offline

 

#23 2013-12-08 12:00:14 pm

McUsrII
Member
Registered: 2012-11-21
Posts: 3046
Website

Re: Miscellanous scripts

Hello.

Should you have the need to debug quicklook, as it stops to work, then start looking for plugins that are in either /Library/QuickLook and ~/Library/QuickLook, and has a modification date back to 2007 … wink

Offline

 

#24 2014-01-07 02:21:36 pm

McUsrII
Member
Registered: 2012-11-21
Posts: 3046
Website

Re: Miscellanous scripts

Hello.

This is  script that installs a git repo for an Xcode 5 project when either you are upgrading the project to Xcode 5, or forgot/refused to install a git repo in the first place.

You should stand on the root folder of the project in a Finder window, and execute the script from there. The folder structure of the Xcode project should be willy nilly, with a folder within the root folder of the project that carries the same name.

The script is kindof a state machine. It works as it should, but may be hard to modify.

You may want to modify it slightly if you are running Xcode 3 or Xcode 4 alongside Xcode 5.

Applescript:

global theLoc

set situ to 1
installGitRepo(situ)
on installGitRepo(situ)
   global theLoc
   tell application "Finder"
       try
           if situ = 1 then
               set theSel to selection
               if theSel is {} then error number 3000
               set theKind to class of item 1 of theSel
               if theKind is not folder then error number 3000
               set didSelect to false
           else
               set theSel to {}
               set end of theSel to choose folder default location theLoc with prompt "Select Xcode root folder."
               set didSelect to true
           end if
           
           set theName to name of item 1 of theSel
           if not didSelect and not (exists folder theName of (item 1 of theSel)) then error number 3001
           set pxPath to quoted form of POSIX path of (item 1 of theSel as alias)
           set repoExists to (do shell script "cd " & pxPath & "; test -d .git && echo \"true\" || echo \"false\"") as boolean
           if repoExists then
               display alert "A git repository is already in place"
               if situ = 2 then set target of Finder window 1 to item 1 of theSel
               set situ to -1
           else
               --every thing so far is okay time to create the git repo.
               set pxPath to quoted form of POSIX path of (item 1 of theSel as alias)
               
               do shell script "cd " & pxPath & " ; mkdir .git ; cat \"UserInterfaceState.xcuserstate
build
*.pbxuser
*.perspectivev3
*.mode1v3
*~
*~.nib
*~.xib
.DS_Store
xcuserdata/\" >.git/.gitignore;git init; git add .; git commit -m \"initial commit\""

               display alert "Successfully created .git repo for Xcode Project " & theName
               if situ = 2 then set target of Finder window 1 to item 1 of theSel
               set situ to 0
           end if
       on error e number n
           if n = -128 then
               set situ to -3
           else if n < 3000 then
               display alert "Unrecoverable error:
"
& e
               set situ to -2
           else if n = 3000 then
               set theTarget to name of its target of Finder window 1 -- as alias as text
               display alert "No folder selected in " & theTarget
               set situ to 2
           else if n = 3001 then
               set theFolder to name of item 1 of theSel
               display alert "No folder of folder " & theFolder & " named " & theFolder & ".
The folder can't be the root folder of an Xcode project."

               set situ to 2
           end if
       end try
       if situ > 0 then set theLoc to target of Finder window 1 as alias
   end tell
   
   if situ > 0 then
       installGitRepo(situ)
   else
       if situ = 0 then
           set theLoc to missing value
           if running of application "Xcode" is true then
               tell application "Finder" to display alert "You must restart Xcode to make it acknowledge the repo."
           else
               tell application "Finder" to display alert "You can start Xcode to use source control."
           end if
       else if situ = -1 then
           tell application "Finder" to display dialog "Do you want to create a repo for another folder?" with icon note
           set situ to 1
           installGitRepo(situ)
       end if
   end if
end installGitRepo

Last edited by McUsrII (2014-01-07 09:00:08 pm)


Filed under: Xcode 5, git

Offline

 

#25 2014-01-07 09:03:22 pm

McUsrII
Member
Registered: 2012-11-21
Posts: 3046
Website

Re: Miscellanous scripts

Hello.

I updated the script above, so that if the folder structure deviates from having subfolder with the same name, then you are allowed to use the same root folder, whence you select the folder the second time around, which you are forced to.

I am a fan of this script, since it lets me play with other peoples examples/code, without fear of not being able to go back to the original, and also without the hassle of having several copies of the same project, and the hurdles of figuring out which is which.


Filed under: Xcode 5, git

Offline

 

Board footer

Powered by FluxBB

RSS (new topics) RSS (active topics)