Mkfifo to add named pipes

Mkfifo to add named pipes

--
--  DASAppDelegate.applescript
--  itunes-concatenator
--
--  Created by David Schlachter on 2014-08-26.
--  Copyright (c) 2014 Red Eft Software. All rights reserved.
--

-- via http://macscripter.net/viewtopic.php?pid=173787 ; apparently needed for using arrays

script DASAppDelegate
	property parent : class "NSObject"

    global these_files, these_times, these_titles, the_index

	-- IBOutlets
	property window : missing value
    property trackTable : missing value
    property catName : missing value
    property catArtist : missing value
    property catAlbum : missing value
    property catComposer : missing value
    property catGenre : missing value
    property catTrack : missing value
    property catTracks : missing value
    property catDisc : missing value
    property catDiscs : missing value

    -- Again, per macscripter, we'll set up bindings for the options
    property pcatName : ""
    property pcatArtist : ""
    property pcatAlbum : ""
    property pcatComposer : ""
    property pcatGenre : ""
    property pcatTrack : ""
    property pcatTracks : ""
    property pcatDisc : ""
    property pcatDiscs : ""

    -- Empty strings for each file name and location
    property pEachName : ""
    property pEachLocation : ""

    property these_titles : {}
    property these_files : {}
    property these_times: {}
    property the_index: {}

    on awakeFromNib()
        --
        -- Check for FFMPEG
        --
        -- (This works, but it's ugly!)
        --
        --
        try
            do shell script "if [[ -r /etc/profile ]];then . /etc/profile;fi;if [[ -r ~/.bashrc ]];then . ~/.bashrc;fi;if [[ -r ~/.bash_profile ]];then . ~/.bash_profile;fi; if [ -x \"`/usr/bin/which ffmpeg`\" ];then exit 0;else exit 1;fi"
        on error number error_number
            display dialog "You must install FFMPEG to continue. \n\nYou may have to install Xcode Command Line Tools and Homebrew first. If you continue, we'll attempt to install them for you if they are not already present. \n\nIf you have already installed FFMPEG, ensure that it is in your bash path." buttons {"Quit","Install FFMPEG"} default button 2
            If button returned of result is "Install FFMPEG" then
                try
                    tell application "Terminal"
                        -- TODO: This should be cleaner -- Terminal in front, only one window, focus back to the cat'er afterwards
                        set newTab to do script "if [[ -r /etc/profile ]];then . /etc/profile;fi;if [[ -r ~/.bashrc ]];then . ~/.bashrc;fi;if [[ -r ~/.bash_profile ]];then . ~/.bash_profile;fi;if [[ -x `which brew` ]];then brew install ffmpeg;else /usr/bin/ruby -e \"$(/usr/bin/curl -fsSL https://raw.github.com/Homebrew/homebrew/go/install)\";brew install ffmpeg;fi"
                        delay 4
                        repeat
                            delay 0.1
                            if not busy of newTab then exit repeat
                        end repeat
                    end tell
                     -- TODO: This needs a better test, i.e., check if ffmpeg is actually accessible on the path
                    display dialog "FFMPEG was successfully installed"
                    -- TODO: This should actually work! (Bring us back to the foreground)
                    activate current application
                on error number error_number
                    display dialog "FFMPEG did not successfully install"
                end try
            end If
            If button returned of result is "Quit" then
                -- Fix!
                current application's NSApp's terminate()
            end If
        end try
    end awakeFromNib

    on btnGetTracks_(sender)
        -- Code to add iTunes tracks to our list
        -- via http://dougscripts.com/itunes/itinfo/info02.php and http://www.randomsequence.com/articles/applescript-to-send-selected-itunes-tracks-using-mail/
        tell application "iTunes"
            set these_titles to {}
            set these_times to {}
            set these_files to {}
            set the_index to {}
            if selection is not {} then -- there ARE tracks selected...
                set mySelection to selection
                set i to 1
                repeat with aTrack in mySelection
                    if class of aTrack is file track then
                        set end of these_titles to ((name of aTrack) as string)
                        set end of these_times to ((time of aTrack) as string)
                        set end of these_files to (posix path of (get location of aTrack))
                        set end of the_index to (count of these_titles)
                    end if
                end repeat
            end if
        end tell
        -- via http://stackoverflow.com/questions/25537750/setstringvalue-with-applescript-list
        set olddelimeters to AppleScript's text item delimiters
        set AppleScript's text item delimiters to "\n"
        set disp_titles to these_titles as string
        trackTable's setStringValue_(disp_titles)
        set AppleScript's text item delimiters to olddelimeters
    end btnGetTracks_

    on btnConcatenate_(sender)
        say "We'll concatenate"
        repeat with theItem in these_titles
            say theItem
        end repeat
        repeat with theIndex in the_index
            set the_shellscript to "/usr/bin/mkfifo /private/tmp/concat" & theIndex as text
            do shell script the_shellscript
        end repeat
    end btnConcatenate_

	on applicationWillFinishLaunching_(aNotification)
		-- Insert code here to initialize your application before any files are opened
	end applicationWillFinishLaunching_

	on applicationShouldTerminate_(sender)
		-- Insert code here to do any housekeeping before your application quits
		return current application's NSTerminateNow
	end applicationShouldTerminate_

end script

--
--  DASAppDelegate.applescript
--  itunes-concatenator
--
--  Created by David Schlachter on 2014-08-26.
--  Copyright (c) 2014 Red Eft Software. All rights reserved.
--

-- via http://macscripter.net/viewtopic.php?pid=173787 ; apparently needed for using arrays

script DASAppDelegate
	property parent : class "NSObject"

    global these_files, these_times, these_titles

	-- IBOutlets
	property window : missing value
    property trackTable : missing value
    property catName : missing value
    property catArtist : missing value
    property catAlbum : missing value
    property catComposer : missing value
    property catGenre : missing value
    property catTrack : missing value
    property catTracks : missing value
    property catDisc : missing value
    property catDiscs : missing value

    -- Again, per macscripter, we'll set up bindings for the options
    property pcatName : ""
    property pcatArtist : ""
    property pcatAlbum : ""
    property pcatComposer : ""
    property pcatGenre : ""
    property pcatTrack : ""
    property pcatTracks : ""
    property pcatDisc : ""
    property pcatDiscs : ""

    -- Empty strings for each file name and location
    property pEachName : ""
    property pEachLocation : ""

    property these_titles : {}
    property these_files : {}
    property these_times: {}

    on awakeFromNib()
        --
        -- Check for FFMPEG
        --
        -- (This works, but it's ugly!)
        --
        --
        try
            do shell script "if [[ -r /etc/profile ]];then . /etc/profile;fi;if [[ -r ~/.bashrc ]];then . ~/.bashrc;fi;if [[ -r ~/.bash_profile ]];then . ~/.bash_profile;fi; if [ -x \"`/usr/bin/which ffmpeg`\" ];then exit 0;else exit 1;fi"
        on error number error_number
            display dialog "You must install FFMPEG to continue. \n\nYou may have to install Xcode Command Line Tools and Homebrew first. If you continue, we'll attempt to install them for you if they are not already present. \n\nIf you have already installed FFMPEG, ensure that it is in your bash path." buttons {"Quit","Install FFMPEG"} default button 2
            If button returned of result is "Install FFMPEG" then
                try
                    tell application "Terminal"
                        -- TODO: This should be cleaner -- Terminal in front, only one window, focus back to the cat'er afterwards
                        set newTab to do script "if [[ -r /etc/profile ]];then . /etc/profile;fi;if [[ -r ~/.bashrc ]];then . ~/.bashrc;fi;if [[ -r ~/.bash_profile ]];then . ~/.bash_profile;fi;if [[ -x `which brew` ]];then brew install ffmpeg;else /usr/bin/ruby -e \"$(/usr/bin/curl -fsSL https://raw.github.com/Homebrew/homebrew/go/install)\";brew install ffmpeg;fi"
                        delay 4
                        repeat
                            delay 0.1
                            if not busy of newTab then exit repeat
                        end repeat
                    end tell
                     -- TODO: This needs a better test, i.e., check if ffmpeg is actually accessible on the path
                    display dialog "FFMPEG was successfully installed"
                    -- TODO: This should actually work! (Bring us back to the foreground)
                    activate current application
                on error number error_number
                    display dialog "FFMPEG did not successfully install"
                end try
            end If
            If button returned of result is "Quit" then
                -- Fix!
                current application's NSApp's terminate()
            end If
        end try
    end awakeFromNib

    on btnGetTracks_(sender)
        -- Code to add iTunes tracks to our list
        -- via http://dougscripts.com/itunes/itinfo/info02.php and http://www.randomsequence.com/articles/applescript-to-send-selected-itunes-tracks-using-mail/
        tell application "iTunes"
            set these_titles to {}
            set these_times to {}
            set these_files to {}
            if selection is not {} then -- there ARE tracks selected...
                set mySelection to selection
                repeat with aTrack in mySelection
                    if class of aTrack is file track then
                        set end of these_titles to ((name of aTrack) as string)
                        set end of these_times to ((time of aTrack) as string)
                        set end of these_files to (posix path of (get location of aTrack))
                    end if
                end repeat
            end if
        end tell
        -- via http://stackoverflow.com/questions/25537750/setstringvalue-with-applescript-list
        set olddelimeters to AppleScript's text item delimiters
        set AppleScript's text item delimiters to "\n"
        set disp_titles to these_titles as string
        trackTable's setStringValue_(disp_titles)
        set AppleScript's text item delimiters to olddelimeters
    end btnGetTracks_

    on btnConcatenate_(sender)
        repeat with theItem in these_titles
            say theItem
        end repeat
    end btnConcatenate_

	on applicationWillFinishLaunching_(aNotification)
		-- Insert code here to initialize your application before any files are opened
	end applicationWillFinishLaunching_

	on applicationShouldTerminate_(sender)
		-- Insert code here to do any housekeeping before your application quits
		return current application's NSTerminateNow
	end applicationShouldTerminate_

end script


timeout set 15 mins

timeout set 15 mins

FasdUAS 1.101.10
k
i
I
.aevtoappnull****
	o0argv
kL

r

l
n
4

cobj
m
o0argv
o0	pathtopsd	pathToPsd
r

l
n
4

cobj
m

o0argv
o0	pathtojsx	pathToJsx
r
[
m
 l!
!n"#
"4$

cobj
$m
#o0argv
o0waittimewaitTime%
%OL&'
&kK(()*
)l*+,
+I
.miscactvnullnull,-.
-I!)/
.PsCSodocnull****
/4!%0

alis
0o#$0	pathtopsd	pathToPsd.12
1t*534
3I,45
.miscDjxMutxt****
5l,06
64,07

file
7o./0	pathtojsx	pathToJsx
4m*+289
8I6;:
.sysodelanullnmbr
:o670waittimewaitTime9;<
;l<<<=>
=I<E?@
.PsCSclosnulldocu
?2<?

docu@A

savo
Am@A
savono  >B
BIFK
.PsCSquitnullnull
'mCC08BIMalisMacintosh HDΘ*SH+t[IAdobe Photoshop CC 2015.appt[J	 Adobe Photoshop CC 2015ΗAt[I#$OMacintosh HD:Applications:Adobe Photoshop CC 2015:Adobe Photoshop CC 2015.app8Adobe Photoshop CC 2015.appMacintosh HD@Applications/Adobe Photoshop CC 2015/Adobe Photoshop CC 2015.app/D
DlEFE
.aevtoappnull****FGH
.aevtoappnull****0argvG0argvHC

cobj0	pathtopsd	pathToPsd0	pathtojsx	pathToJsx0waittimewaitTime
.miscactvnullnull

alis
.PsCSodocnull****

file
.miscDjxMutxt****
.sysodelanullnmbr

docu

savo
savono
.PsCSclosnulldocu
.PsCSquitnullnullMk/EOl/EOjm/EO2*jO*/jOn*/j
oOjO*-lO*jUascr
ޭ

FasdUAS 1.101.10
k
i
I
.aevtoappnull****
	o0argv
kI

r

l
n
4

cobj
m
o0argv
o0	pathtopsd	pathToPsd
r

l
n
4

cobj
m

o0argv
o0	pathtojsx	pathToJsx
r
[
m
 l!
!n"#
"4$

cobj
$m
#o0argv
o0waittimewaitTime%
%OI&'
&kH(()*
)I
.miscactvnullnull*+,
+I!)-
.PsCSodocnull****
-4!%.

alis
.o#$0	pathtopsd	pathToPsd,/0
/I*21
.miscDjxMutxt****
1l*.2
24*.3

file
3o,-0	pathtojsx	pathToJsx045
4l33567
6I388
.sysodelanullnmbr
8o340waittimewaitTime79:
9l99:;<
;I9B=>
.PsCSclosnulldocu
=29<

docu>?

savo
?m=>
savono  <@
@ICH
.PsCSquitnullnull
'mAA08BIMalisMacintosh HDΘ*SH+t[IAdobe Photoshop CC 2015.appt[J	 Adobe Photoshop CC 2015ΗAt[I#$OMacintosh HD:Applications:Adobe Photoshop CC 2015:Adobe Photoshop CC 2015.app8Adobe Photoshop CC 2015.appMacintosh HD@Applications/Adobe Photoshop CC 2015/Adobe Photoshop CC 2015.app/B
BlCDC
.aevtoappnull****DEF
.aevtoappnull****0argvE0argvFA

cobj0	pathtopsd	pathToPsd0	pathtojsx	pathToJsx0waittimewaitTime
.miscactvnullnull

alis
.PsCSodocnull****

file
.miscDjxMutxt****
.sysodelanullnmbr

docu

savo
savono
.PsCSclosnulldocu
.PsCSquitnullnullJk/EOl/EOjm/EO/*jO*/jO*/j	Oj
O*-lO*jUascrޭ


Update window arrange script

Update window arrange script

FasdUAS 1.101.10
k
i
I	0resize_app_window

o0app_name

o0win_position

o0win_size
Z=
=
n
1

prun
4

capp
o0app_name
m
boovtrue
O9
O8
k7
r&
J  !
 n"#
"4$

cobj
$m
#o0win_position!%
%n&'
&4(

cobj
(m
'o0win_position
n)*
)1#%

posn
*l #+
+2 #

cwin,
,r'7-.
-J'1//01
0n'+23
24(+4

cobj
4m)*
3o'(0win_size15
5n+/67
64,/8

cobj
8m-.
7o+,0win_size
.n9:
9146

ptsz
:l14;
;214

cwin
4<

prcs
<o0app_name
m==sevsalis\Macintosh HDBDSystem Events.app
 cuCoreServices0/:System:Library:CoreServices:System Events.app/$System Events.appMacintosh HD-System/Library/CoreServices/System Events.app/>?
>l?@A
@lB
BrCD
CJEEFG
FmGH
Hm$
Do0wide_center_positionAIJ
Il
K
Kr
LM
LJNNOP
OmPQ
Qm	Q
Mo0wide_center_sizeJRS
RlSTU
TlV
VIW0resize_app_windowWXY
XmZZ[[1Password 7Y\]
\o0wide_center_position]^
^o0wide_center_sizeU_`
_la
aIb0resize_app_windowbcd
cmeeffCalendardgh
go0wide_center_positionhi
io0wide_center_size`jk
jl (l
lI (m0resize_app_windowmno
nm!"ppqqFantasticalors
ro"#0wide_center_positionst
to#$0wide_center_sizekuv
ul)1w
wI)1x0resize_app_windowxyz
ym*+{{||Google Chromez}~
}o+,0wide_center_position~
o,-0wide_center_sizev
l2:
I2:0resize_app_window
m34Linear
o450wide_center_position
o560wide_center_size
l;C
I;C0resize_app_window
m<=Mail
o=>0wide_center_position
o>?0wide_center_size
lDR
IDR0resize_app_window
mEFMessages
JFJ
mFG
mGH$
JJN
mJK?
mKLQ
lS[
IS[0resize_app_window
mTU
Music
oUV0wide_center_position
oVW0wide_center_size
l\f
I\f0resize_app_window
m]`
Notes
o`a0wide_center_position
oab0wide_center_size
lgq
Igq0resize_app_window
mhkNotion
okl0wide_center_position
olm~~0wide_center_size
lr|}|
Ir|{z{0resize_app_window
msvPreview
ovwyy0wide_center_positionx
owxww0wide_center_sizexz}|
l}vu
I}tst0resize_app_window
m~Safari
orr0wide_center_positionq
opp0wide_center_sizeqsvu
lon
Imlm0resize_app_window
m
Slack
okk0wide_center_positionj
oii0wide_center_sizejlon
lhg
Ifef0resize_app_window
mSpotify
odd0wide_center_positionc
obb0wide_center_sizecehg
la`
I_^_0resize_app_window
mTextEdit
J
m]]\
m[[\Z
J
mYYX
mWWXZ^a`	V
	l
UT

ISRS0resize_app_window

mTweetbot

J
mQQP
mOO$PN
J
mMM?L
mKKQLNRUTVJJIHGFI0resize_app_window
H.aevtoappnull****G0wide_center_positionF0wide_center_sizeEDC !BE0resize_app_windowDA"A"@?>@0app_name?0win_position>0win_sizeC =<;=0app_name<0win_position;0win_size!:9=87654
:
capp
9
prun
8
prcs
7
cobj
6
cwin
5
posn
4
ptszB>*/,e3+*/#k/l/lv*-,FOk/l/lv*-,FUUYh3#21$%0
3.aevtoappnull****
#k&&@''I((T))_**j++u,,--..//0011223344556677	//21$%.-,+*)Z(ep{'&%$.-$,0wide_center_position+*Q)0wide_center_size(0resize_app_window'?&%$0lvEOlvEO*m+O*m+O*m+O*m+O*m+O*m+O*lvlvm+O*m+O*am+O*am+O*am+O*am+O*am+O*am+O*aalvaalvm+O*alvlvm+#8#8"!"!$ 9 9Qascr
ޭ

FasdUAS 1.101.10
k
i
I	0resize_app_window

o0app_name

o0win_position

o0win_size
Z=
=
n
1

prun
4

capp
o0app_name
m
boovtrue
O9
O8
k7
r&
J  !
 n"#
"4$

cobj
$m
#o0win_position!%
%n&'
&4(

cobj
(m
'o0win_position
n)*
)1#%

posn
*l #+
+2 #

cwin,
,r'7-.
-J'1//01
0n'+23
24(+4

cobj
4m)*
3o'(0win_size15
5n+/67
64,/8

cobj
8m-.
7o+,0win_size
.n9:
9146

ptsz
:l14;
;214

cwin
4<

prcs
<o0app_name
m==sevsalis\Macintosh HDBDSystem Events.app
 cuCoreServices0/:System:Library:CoreServices:System Events.app/$System Events.appMacintosh HD-System/Library/CoreServices/System Events.app/>?
>l?@A
@lB
BrCD
CJEEFG
FmGH
Hm$
Do0wide_center_positionAIJ
Il
K
Kr
LM
LJNNOP
OmPQ
Qm	Q
Mo0wide_center_sizeJRS
RlSTU
TlV
VIW0resize_app_windowWXY
XmZZ[[1Password 7Y\]
\o0wide_center_position]^
^o0wide_center_sizeU_`
_la
aIb0resize_app_windowbcd
cmeeffCalendardgh
go0wide_center_positionhi
io0wide_center_size`jk
jl (l
lI (m0resize_app_windowmno
nm!"ppqqFantasticalors
ro"#0wide_center_positionst
to#$0wide_center_sizekuv
ul)1w
wI)1x0resize_app_windowxyz
ym*+{{||Google Chromez}~
}o+,0wide_center_position~
o,-0wide_center_sizev
l2:
I2:0resize_app_window
m34Linear
o450wide_center_position
o560wide_center_size
l;C
I;C0resize_app_window
m<=Mail
o=>0wide_center_position
o>?0wide_center_size
lDR
IDR0resize_app_window
mEFMessages
JFJ
mFG
mGH$
JJN
mJK?
mKLQ
lS[
IS[0resize_app_window
mTU
Music
oUV0wide_center_position
oVW0wide_center_size
l\f
I\f0resize_app_window
m]`
Notes
o`a0wide_center_position
oab0wide_center_size
lgq
Igq0resize_app_window
mhkNotion
okl0wide_center_position
olm~~0wide_center_size
lr|}|
Ir|{z{0resize_app_window
msvPreview
ovwyy0wide_center_positionx
owxww0wide_center_sizexz}|
l}vu
I}tst0resize_app_window
m~Safari
orr0wide_center_positionq
opp0wide_center_sizeqsvu
lon
Imlm0resize_app_window
m
Slack
okk0wide_center_positionj
oii0wide_center_sizejlon
lhg
Ifef0resize_app_window
mSpotify
odd0wide_center_positionc
obb0wide_center_sizecehg
la`
I_^_0resize_app_window
mTextEdit
J
m]]\
m[[\Z
J
mYYX
mWWXZ^a`	V
	l
UT

ISRS0resize_app_window

mTweetbot

J
mQQP
mOO$PN
J
mMM?L
mKKQLNRUTVJJIHI0resize_app_window
H.aevtoappnull****GFEDG0resize_app_windowFC C BA@B0app_nameA0win_position@0win_sizeE?>=?0app_name>0win_position=0win_size<;=:9876
<
capp
;
prun
:
prcs
9
cobj
8
cwin
7
posn
6
ptszD>*/,e3+*/#k/l/lv*-,FOk/l/lv*-,FUUYh5!43"#2
5.aevtoappnull****
!k$$@%%I&&T''_((j))u**++,,--..//001122334455	1143"#0/.-,+Z*ep{)('&0/$.0wide_center_position-,Q+0wide_center_size*0resize_app_window)?('&2lvEOlvEO*m+O*m+O*m+O*m+O*m+O*m+O*lvlvm+O*m+O*am+O*am+O*am+O*am+O*am+O*am+O*aalvaalvm+O*alvlvm+ascr
ޭ


Update script to open DerivedData folder

use scripting additions
use framework "Foundation"
property NSString : a reference to current application's NSString

-- Helper

on myRemoveLastPath(myPath)
set myString to NSString's stringWithString:myPath
set removedLastPathString to myString's stringByDeletingLastPathComponent
removedLastPathString as text
end myRemoveLastPath

on myFolderExists(myFolder) -- (String) as Boolean
tell application "System Events"
if exists folder myFolder then
return true
else
return false
end if
end tell
end myFolderExists

-- Path

on myHomePath()
tell application "System Events"
"/Users/" & (name of current user)
end tell
end myHomePath

on myLibraryPath()
myHomePath() & "/Library"
end myLibraryPath

on myXcodePath()
myLibraryPath() & "/Developer/Xcode"
end myXcodePath

on myUserDataPath()
myXcodePath() & "/UserData"
end myUserDataPath

on myProjectPath()
tell application "Xcode"
tell active workspace document
set myPath to path
end tell
end tell
myRemoveLastPath(myPath)
end myProjectPath

-- Generic Open

on myOpenFolder(myPath)
tell application "Finder"
activate
open myPath as POSIX file
end tell
end myOpenFolder

on myOpeniTerm(myPath)
tell application "Finder"
do shell script "open -a iTerm " & quoted form of myPath
end tell
end myOpeniTerm

-- Open

on myOpenThemesFolder()
set myPath to myUserDataPath() & "/FontAndColorThemes/"
myOpenFolder(myPath)
end myOpenThemesFolder

on myOpenCodeSnippetsFolder()
set myPath to myUserDataPath() & "/CodeSnippets/"
myOpenFolder(myPath)
end myOpenCodeSnippetsFolder

on myOpenDeviceSupportFolder()
set myPath to "/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/DeviceSupport"
myOpenFolder(myPath)
end myOpenDeviceSupportFolder

on myOpenArchivesFolder()
set myPath to myXcodePath() & "/Archives/"
myOpenFolder(myPath)
end myOpenArchivesFolder

on myOpenProvisioningProfileFolder()
set myPath to myLibraryPath() & "/MobileDevice/Provisioning Profiles"
myOpenFolder(myPath)
end myOpenProvisioningProfileFolder

on myOpenProjectFolder()
set myPath to myProjectPath()
myOpenFolder(myPath)
end myOpenProjectFolder

on myOpeniTermForCurrentProject()
set myPath to myProjectPath()
myOpeniTerm(myPath)
end myOpeniTermForCurrentProject

on myOpenDerivedDataFolder()
set myRelativePath to myProjectPath() & "/DerivedData/"
if myFolderExists(myRelativePath) then
myOpenFolder(myRelativePath)
else
myOpenFolder(myXcodePath() & "/DerivedData/")
end if
end myOpenDerivedDataFolder

myOpenDerivedDataFolder()

use scripting additions
use framework "Foundation"
property NSString : a reference to current application's NSString

-- Helper

on myRemoveLastPath(myPath)
set myString to NSString's stringWithString:myPath
set removedLastPathString to myString's stringByDeletingLastPathComponent
removedLastPathString as text
end myRemoveLastPath

-- Path

on myHomePath()
tell application "System Events"
"/Users/" & (name of current user)
end tell
end myHomePath

on myLibraryPath()
myHomePath() & "/Library"
end myLibraryPath

on myXcodePath()
myLibraryPath() & "/Developer/Xcode"
end myXcodePath

on myUserDataPath()
myXcodePath() & "/UserData"
end myUserDataPath

on myProjectPath()
tell application "Xcode"
tell active workspace document
set myPath to path
end tell
end tell
myRemoveLastPath(myPath)
end myProjectPath

-- Generic Open

on myOpenFolder(myPath)
tell application "Finder"
activate
open myPath as POSIX file
end tell
end myOpenFolder

on myOpeniTerm(myPath)
tell application "Finder"
do shell script "open -a iTerm " & quoted form of myPath
end tell
end myOpeniTerm

-- Open

on myOpenThemesFolder()
set myPath to myUserDataPath() & "/FontAndColorThemes/"
myOpenFolder(myPath)
end myOpenThemesFolder

on myOpenCodeSnippetsFolder()
set myPath to myUserDataPath() & "/CodeSnippets/"
myOpenFolder(myPath)
end myOpenCodeSnippetsFolder

on myOpenDeviceSupportFolder()
set myPath to "/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/DeviceSupport"
myOpenFolder(myPath)
end myOpenDeviceSupportFolder

on myOpenArchivesFolder()
set myPath to myXcodePath() & "/Archives/"
myOpenFolder(myPath)
end myOpenArchivesFolder

on myOpenProvisioningProfileFolder()
set myPath to myLibraryPath() & "/MobileDevice/Provisioning Profiles"
myOpenFolder(myPath)
end myOpenProvisioningProfileFolder

on myOpenProjectFolder()
set myPath to myProjectPath()
myOpenFolder(myPath)
end myOpenProjectFolder

on myOpeniTermForCurrentProject()
set myPath to myProjectPath()
myOpeniTerm(myPath)
end myOpeniTermForCurrentProject


Update Vagrant path

Update Vagrant path

set open_vagrant to "cd ~/uberVU/puppet/hs_analytics_vagrant && git pull && vagrant up"

tell application "iTerm"
	activate
	try
		set mysession to current session of current terminal
	on error
		set myterm to (make new terminal)
		tell myterm
			launch session "Default"
			set mysession to current session
		end tell
	end try

	tell mysession
		write text open_vagrant
	end tell
end tell

set open_vagrant to "cd ~/uberVU/puppet && vagrant up"

tell application "iTerm"
	activate
	try
		set mysession to current session of current terminal
	on error
		set myterm to (make new terminal)
		tell myterm
			launch session "Default"
			set mysession to current session
		end tell
	end try

	tell mysession
		write text open_vagrant
	end tell
end tell


Re-add logging to `AlfredBundler.scpt`

Re-add logging to `AlfredBundler.scpt`

(* GLOBAL PROPERTIES *)

property BUNDLER_VERSION : "devel"

--# Used for notifications, paths
property BUNDLER_ID : "com.hackademic.alfred-bundler-applescript"

--# Bundler paths
property _home : POSIX path of (path to "cusr" as text)
property BUNDLER_DIR : (_home) & "Library/Application Support/Alfred 2/Workflow Data/alfred.bundler-" & BUNDLER_VERSION
property DATA_DIR : BUNDLER_DIR & "/data"
property CACHE_DIR : (_home) & "Library/Caches/com.runningwithcrayons.Alfred-2/Workflow Data/alfred.bundler-" & BUNDLER_VERSION

--# Main Applescript library
property BUNDLER_AS_LIB : BUNDLER_DIR & "/bundler/AlfredBundler.scpt"

--# Root directory under which workflow-specific Python libraries are installed
property APPLESCRIPT_LIB_DIR : DATA_DIR & "/assets/applescript"

--# Root directory under which workflow-specific Python libraries are installed
property UTILITIES_LIB_DIR : DATA_DIR & "/assets/utility"

--# Wrappers module path
property WRAPPERS_DIR : BUNDLER_DIR & "/bundler/includes/wrappers/applescript"

--# Where helper scripts and metadata are stored
property HELPER_DIR : APPLESCRIPT_LIB_DIR & "/" & BUNDLER_ID

--# Directory for Bundler icons
property BUNDLER_ICONS_LIB : DATA_DIR & "/assets/icons"

--# Where color alternatives are cached
property COLOR_CACHE : DATA_DIR & "/color-cache"

(* GLOBAL VARIABLES *)

--# Where installer.sh can be downloaded from
global BASH_BUNDLET_URL
set BASH_BUNDLET_URL to my _format("https://raw.githubusercontent.com/shawnrice/alfred-bundler/{}/bundler/bundlets/alfred.bundler.sh", BUNDLER_VERSION)

--# Bundler log file
global BUNDLER_LOGFILE
set BUNDLER_LOGFILE to my _format((DATA_DIR & "/logs/bundler-{}.log"), BUNDLER_VERSION)

--# The actual bundler module will be imported into this variable
property _bundler : missing value

(* ///
USER API
/// *)

on load_utility(_name, _version, _json)
	--# partial support for "optional" args in Applescript
	if my _is_empty(_version) then
		set _version to "latest"
	end if
	if my _is_empty(_json) then
		set _json to ""
	end if
	--# path to specific utility
	set utility to UTILITIES_LIB_DIR & "/" & _name & "/" & _version
	--# if utility isn't already installed
	if my _folder_exists(utility) = false then
		set bash_bundlet to (my _dirname(BUNDLER_AS_LIB)) & "bundlets/alfred.bundler.sh"
		if my _file_exists(bash_bundlet) = true then
			set bash_bundlet_cmd to quoted form of bash_bundlet
			set cmd to my _join({bash_bundlet_cmd, "utility", _name, _version, _json}, space)
			set cmd to my _prepare_cmd(cmd)
			do shell script cmd
		end if

		--# if utility is already installed
	else
		--# read utilities invoke file
		set invoke_file to utility & "/invoke"
		if my _file_exists(invoke_file) = true then
			set invoke_path to my _read_file(invoke_file)
			--# combine utility path with invoke path
			set full_path to utility & "/" & invoke_path
			return full_path
		end if
	end if
end load_utility

on get_icon(_font, _name, _color, _alter)
	--# partial support for "optional" args in Applescript
	if my _is_empty(_color) then
		set _color to "000000"
		if my _is_empty(_alter) then
			set _alter to true
		end if
	end if
	if my _is_empty(_alter) then
		set _alter to false
	end if

	set icon to BUNDLER_ICONS_LIB & "/" & _font & "/" & _color & "/" & _name
	if my _folder_exists(icon) = false then
		set bash_bundlet to (my _dirname(BUNDLER_AS_LIB)) & "bundlets/alfred.bundler.sh"
		if my _file_exists(bash_bundlet) = true then
			set bash_bundlet_cmd to quoted form of bash_bundlet
			set cmd to my _join({bash_bundlet_cmd, "icon", _font, _name, _color, _alter}, space)
			set cmd to my _prepare_cmd(cmd)
			do shell script cmd
		end if
	else
		return icon
	end if
end get_icon

(* ///
MAIN ACTION HANDLERS
/// *)

on _log(_handler, _level, _message)
	--# Ensure log file exists
	my _check_file(BUNDLER_LOGFILE)
	delay 0.1 -- delay to ensure IO action is completed
	--# Prepare time string format %Y-%m-%d %H:%M:%S
	set log_time to "[" & (my date_format()) & "]"
	set formatted_time to text items 1 thru -4 of (time string of (current date)) as string
	set error_time to "[" & formatted_time & "]"
	--# Prepare location message
	set _location to "[bundler.scpt:" & _handler & "]"
	--# Prepare level message
	set _level to "[" & _level & "]"
	--# Generate full error message for logging
	set log_msg to (ASCII character 10) & log_time & space & _location & space & _level & tab & _message
	my write_to_file(log_msg, BUNDLER_LOGFILE, true)
	--# Generate regular error message for returning to user
	set error_msg to error_time & space & _location & space & _level & tab & _message
	return error_msg
end _log

(* ///
SUB-ACTION HANDLERS
/// *)

on date_format() -- Old_date is text, not a date.
	set {year:y, month:m, day:d} to current date
	set date_num to (y * 10000 + m * 100 + d) as string
	set formatted_date to ((text 1 thru 4 of date_num) & "-" & (text 5 thru 6 of date_num) & "-" & (text 7 thru 8 of date_num))
	set formatted_time to text items 1 thru -4 of (time string of (current date)) as string
	return formatted_date & space & formatted_time
end date_format

on _read_file(target_file)
	open for access POSIX file target_file
	set _contents to (read target_file)
	close access target_file
	return _contents
end _read_file

on _prepare_cmd(cmd)
	set pwd to quoted form of (my _pwd())
	return "cd " & pwd & "; bash " & cmd
end _prepare_cmd

(* ///
IO HELPER FUNCTIONS
/// *)

on write_to_file(this_data, target_file, append_data)
	try
		set the target_file to the target_file as string
		set the open_target_file to open for access POSIX file target_file with write permission
		if append_data is false then set eof of the open_target_file to 0
		write this_data to the open_target_file starting at eof
		close access the open_target_file
		return true
	on error
		try
			close access file target_file
		end try
		return false
	end try
end write_to_file

--#
on _pwd()
	set {ASTID, AppleScript's text item delimiters} to {AppleScript's text item delimiters, "/"}
	set _path to (text items 1 thru -2 of (POSIX path of (path to me)) as string) & "/"
	set AppleScript's text item delimiters to ASTID
	return _path
end _pwd

on _dirname(_file)
	set {ASTID, AppleScript's text item delimiters} to {AppleScript's text item delimiters, "/"}
	set _path to (text items 1 thru -2 of _file as string) & "/"
	set AppleScript's text item delimiters to ASTID
	return _path
end _dirname

on _check_dir(_folder)
	if not my _folder_exists(_folder) then
		do shell script "mkdir -p " & (quoted form of _folder)
	end if
	return _folder
end _check_dir

on _check_file(_path)
	if not my _file_exists(_path) then
		set _dir to _dirname(_path)
		my _check_dir(_dir)
		delay 0.1
		do shell script "touch " & (quoted form of _path)
	end if
end _check_file

--#  handler to check if a folder exists
on _folder_exists(_folder)
	if my _path_exists(_folder) then
		tell application "System Events"
			return (class of (disk item _folder) is folder)
		end tell
	end if
	return false
end _folder_exists

--# handler to check if a file exists
on _file_exists(_file)
	if my _path_exists(_file) then
		tell application "System Events"
			return (class of (disk item _file) is file)
		end tell
	end if
	return false
end _file_exists

--#  handler to check if a path exists
on _path_exists(_path)
	if _path is missing value or my _is_empty(_path) then return false

	try
		if class of _path is alias then return true
		if _path contains ":" then
			alias _path
			return true
		else if _path contains "/" then
			POSIX file _path as alias
			return true
		else
			return false
		end if
	on error msg
		return false
	end try
end _path_exists

(* ///
TEXT HELPER FUNCTIONS
/// *)

on _split(str, delimiter)
	local delimiter, str, ASTID
	set ASTID to AppleScript's text item delimiters
	try
		set AppleScript's text item delimiters to delimiter
		set str to text items of str
		set AppleScript's text item delimiters to ASTID
		return str --> list
	on error msg number num
		set AppleScript's text item delimiters to ASTID
		error "Can't explode: " & msg number num
	end try
end _split

--# format string á la Python
on _format(str, arg)
	local ASTID, str, arg, lst
	set ASTID to AppleScript's text item delimiters
	try
		considering case
			set AppleScript's text item delimiters to "{}"
			set lst to every text item of str
			set AppleScript's text item delimiters to arg
			set str to lst as string
		end considering
		set AppleScript's text item delimiters to ASTID
		return str
	on error msg number num
		set AppleScript's text item delimiters to ASTID
		error "Can't replaceString: " & msg number num
	end try
end _format

--# removes white space surrounding a string
on _trim(str)
	if class of str is not text or class of str is not string or str is missing value then return str
	if str is "" then return str
	repeat while str begins with " "
		try
			set str to items 2 thru -1 of str as text
		on error msg
			return ""
		end try
	end repeat
	repeat while str ends with " "
		try
			set str to items 1 thru -2 of str as text
		on error
			return ""
		end try
	end repeat
	return str
end _trim

on _join(pieces, delim)
	local delim, pieces, ASTID
	set ASTID to AppleScript's text item delimiters
	try
		set AppleScript's text item delimiters to delim
		set pieces to "" & pieces
		set AppleScript's text item delimiters to ASTID
		return pieces --> text
	on error emsg number eNum
		set AppleScript's text item delimiters to ASTID
		error "Can't implode: " & emsg number eNum
	end try
end _join

(* ///
LOWER LEVEL HELPER FUNCTIONS
/// *)

--# checks if a value is empty
on _is_empty(str)
	if {true, false} contains str then return false
	if str is missing value then return true
	return length of (my _trim(str)) is 0
end _is_empty

--TESTING!!
on test()
	set as_pwd to POSIX path of (path to me) as string
	set pwd to quoted form of my _dirname(as_pwd)
	set cmd to quoted form of "/Users/smargheim/Documents/DEVELOPMENT/GitHub/alfred-bundler/bundler/bundlets/TEST.sh"
	set sh_pwd to do shell script "cd " & pwd & "; bash " & cmd

	return "Applescript PWD: " & as_pwd & return & "Shell PWD: " & sh_pwd

end test

(* GLOBAL PROPERTIES *)

property BUNDLER_VERSION : "devel"

--# Used for notifications, paths
property BUNDLER_ID : "com.hackademic.alfred-bundler-applescript"

--# Bundler paths
property _home : POSIX path of (path to "cusr" as text)
property BUNDLER_DIR : (_home) & "Library/Application Support/Alfred 2/Workflow Data/alfred.bundler-" & BUNDLER_VERSION
property DATA_DIR : BUNDLER_DIR & "/data"
property CACHE_DIR : (_home) & "Library/Caches/com.runningwithcrayons.Alfred-2/Workflow Data/alfred.bundler-" & BUNDLER_VERSION

--# Main Applescript library
property BUNDLER_AS_LIB : BUNDLER_DIR & "/bundler/AlfredBundler.scpt"

--# Root directory under which workflow-specific Python libraries are installed
property APPLESCRIPT_LIB_DIR : DATA_DIR & "/assets/applescript"

--# Root directory under which workflow-specific Python libraries are installed
property UTILITIES_LIB_DIR : DATA_DIR & "/assets/utility"

--# Wrappers module path
property WRAPPERS_DIR : BUNDLER_DIR & "/bundler/includes/wrappers/applescript"

--# Where helper scripts and metadata are stored
property HELPER_DIR : APPLESCRIPT_LIB_DIR & "/" & BUNDLER_ID

--# Directory for Bundler icons
property BUNDLER_ICONS_LIB : DATA_DIR & "/assets/icons"

--# Where color alternatives are cached
property COLOR_CACHE : DATA_DIR & "/color-cache"

(* GLOBAL VARIABLES *)

--# Where installer.sh can be downloaded from
global BASH_BUNDLET_URL
set BASH_BUNDLET_URL to my _format("https://raw.githubusercontent.com/shawnrice/alfred-bundler/{}/bundler/bundlets/alfred.bundler.sh", BUNDLER_VERSION)

--# Bundler log file
global BUNDLER_LOGFILE
set BUNDLER_LOGFILE to my _format((DATA_DIR & "/logs/bundler-{}.log"), BUNDLER_VERSION)

--# The actual bundler module will be imported into this variable
property _bundler : missing value

(* ///
USER API
/// *)

on load_utility(_name, _version, _json)
	--# partial support for "optional" args in Applescript
	if my _is_empty(_version) then
		set _version to "latest"
	end if
	if my _is_empty(_json) then
		set _json to ""
	end if
	--# path to specific utility
	set utility to UTILITIES_LIB_DIR & "/" & _name & "/" & _version
	--# if utility isn't already installed
	if my _folder_exists(utility) = false then
		set bash_bundlet to (my _dirname(BUNDLER_AS_LIB)) & "bundlets/alfred.bundler.sh"
		if my _file_exists(bash_bundlet) = true then
			set bash_bundlet_cmd to quoted form of bash_bundlet
			set cmd to my _join({bash_bundlet_cmd, "utility", _name, _version, _json}, space)
			set cmd to my _prepare_cmd(cmd)
			do shell script cmd
		end if

		--# if utility is already installed
	else
		--# read utilities invoke file
		set invoke_file to utility & "/invoke"
		if my _file_exists(invoke_file) = true then
			set invoke_path to my _read_file(invoke_file)
			--# combine utility path with invoke path
			set full_path to utility & "/" & invoke_path
			return full_path
		end if
	end if
end load_utility

on get_icon(_font, _name, _color, _alter)
	--# partial support for "optional" args in Applescript
	if my _is_empty(_color) then
		set _color to "000000"
		if my _is_empty(_alter) then
			set _alter to true
		end if
	end if
	if my _is_empty(_alter) then
		set _alter to false
	end if

	set icon to BUNDLER_ICONS_LIB & "/" & _font & "/" & _color & "/" & _name
	if my _folder_exists(icon) = false then
		set bash_bundlet to (my _dirname(BUNDLER_AS_LIB)) & "bundlets/alfred.bundler.sh"
		if my _file_exists(bash_bundlet) = true then
			set bash_bundlet_cmd to quoted form of bash_bundlet
			set cmd to my _join({bash_bundlet_cmd, "icon", _font, _name, _color, _alter}, space)
			set cmd to my _prepare_cmd(cmd)
			do shell script cmd
		end if
	else
		return icon
	end if
end get_icon

(* ///
MAIN ACTION HANDLERS
/// *)

(* ///
SUB-ACTION HANDLERS
/// *)

on date_format() -- Old_date is text, not a date.
	set {year:y, month:m, day:d} to current date
	set date_num to (y * 10000 + m * 100 + d) as string
	set formatted_date to ((text 1 thru 4 of date_num) & "-" & (text 5 thru 6 of date_num) & "-" & (text 7 thru 8 of date_num))
	set formatted_time to text items 1 thru -4 of (time string of (current date)) as string
	return formatted_date & space & formatted_time
end date_format

on _read_file(target_file)
	open for access POSIX file target_file
	set _contents to (read target_file)
	close access target_file
	return _contents
end _read_file

on _prepare_cmd(cmd)
	set pwd to quoted form of (my _pwd())
	return "cd " & pwd & "; bash " & cmd
end _prepare_cmd

(* ///
IO HELPER FUNCTIONS
/// *)

on write_to_file(this_data, target_file, append_data)
	try
		set the target_file to the target_file as string
		set the open_target_file to open for access POSIX file target_file with write permission
		if append_data is false then set eof of the open_target_file to 0
		write this_data to the open_target_file starting at eof
		close access the open_target_file
		return true
	on error
		try
			close access file target_file
		end try
		return false
	end try
end write_to_file

--#
on _pwd()
	set {ASTID, AppleScript's text item delimiters} to {AppleScript's text item delimiters, "/"}
	set _path to (text items 1 thru -2 of (POSIX path of (path to me)) as string) & "/"
	set AppleScript's text item delimiters to ASTID
	return _path
end _pwd

on _dirname(_file)
	set {ASTID, AppleScript's text item delimiters} to {AppleScript's text item delimiters, "/"}
	set _path to (text items 1 thru -2 of _file as string) & "/"
	set AppleScript's text item delimiters to ASTID
	return _path
end _dirname

on _check_dir(_folder)
	if not my _folder_exists(_folder) then
		do shell script "mkdir -p " & (quoted form of _folder)
	end if
	return _folder
end _check_dir

on _check_file(_path)
	if not my _file_exists(_path) then
		set _dir to _dirname(_path)
		my _check_dir(_dir)
		delay 0.1
		do shell script "touch " & (quoted form of _path)
	end if
end _check_file

--#  handler to check if a folder exists
on _folder_exists(_folder)
	if my _path_exists(_folder) then
		tell application "System Events"
			return (class of (disk item _folder) is folder)
		end tell
	end if
	return false
end _folder_exists

--# handler to check if a file exists
on _file_exists(_file)
	if my _path_exists(_file) then
		tell application "System Events"
			return (class of (disk item _file) is file)
		end tell
	end if
	return false
end _file_exists

--#  handler to check if a path exists
on _path_exists(_path)
	if _path is missing value or my _is_empty(_path) then return false

	try
		if class of _path is alias then return true
		if _path contains ":" then
			alias _path
			return true
		else if _path contains "/" then
			POSIX file _path as alias
			return true
		else
			return false
		end if
	on error msg
		return false
	end try
end _path_exists

(* ///
TEXT HELPER FUNCTIONS
/// *)

on _split(str, delimiter)
	local delimiter, str, ASTID
	set ASTID to AppleScript's text item delimiters
	try
		set AppleScript's text item delimiters to delimiter
		set str to text items of str
		set AppleScript's text item delimiters to ASTID
		return str --> list
	on error msg number num
		set AppleScript's text item delimiters to ASTID
		error "Can't explode: " & msg number num
	end try
end _split

--# format string á la Python
on _format(str, arg)
	local ASTID, str, arg, lst
	set ASTID to AppleScript's text item delimiters
	try
		considering case
			set AppleScript's text item delimiters to "{}"
			set lst to every text item of str
			set AppleScript's text item delimiters to arg
			set str to lst as string
		end considering
		set AppleScript's text item delimiters to ASTID
		return str
	on error msg number num
		set AppleScript's text item delimiters to ASTID
		error "Can't replaceString: " & msg number num
	end try
end _format

--# removes white space surrounding a string
on _trim(str)
	if class of str is not text or class of str is not string or str is missing value then return str
	if str is "" then return str
	repeat while str begins with " "
		try
			set str to items 2 thru -1 of str as text
		on error msg
			return ""
		end try
	end repeat
	repeat while str ends with " "
		try
			set str to items 1 thru -2 of str as text
		on error
			return ""
		end try
	end repeat
	return str
end _trim

on _join(pieces, delim)
	local delim, pieces, ASTID
	set ASTID to AppleScript's text item delimiters
	try
		set AppleScript's text item delimiters to delim
		set pieces to "" & pieces
		set AppleScript's text item delimiters to ASTID
		return pieces --> text
	on error emsg number eNum
		set AppleScript's text item delimiters to ASTID
		error "Can't implode: " & emsg number eNum
	end try
end _join

(* ///
LOWER LEVEL HELPER FUNCTIONS
/// *)

--# checks if a value is empty
on _is_empty(str)
	if {true, false} contains str then return false
	if str is missing value then return true
	return length of (my _trim(str)) is 0
end _is_empty

--TESTING!!
on test()
	set as_pwd to POSIX path of (path to me) as string
	set pwd to quoted form of my _dirname(as_pwd)
	set cmd to quoted form of "/Users/smargheim/Documents/DEVELOPMENT/GitHub/alfred-bundler/bundler/bundlets/TEST.sh"
	set sh_pwd to do shell script "cd " & pwd & "; bash " & cmd

	return "Applescript PWD: " & as_pwd & return & "Shell PWD: " & sh_pwd

end test