Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Alfred v2.3 feedback upgrades #6

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
84 changes: 58 additions & 26 deletions workflows.php
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -179,14 +179,14 @@ public function toxml( $a=null, $format='array' ) {

$items = new SimpleXMLElement("<items></items>"); // Create new XML element

foreach( $a as $b ): // Lop through each object in the array
foreach( $a as $b ): // Loop through each object in the array
$c = $items->addChild( 'item' ); // Add a new 'item' element for each object
$c_keys = array_keys( $b ); // Grab all the keys for that item
foreach( $c_keys as $key ): // For each of those keys
if ( $key == 'uid' ):
$c->addAttribute( 'uid', $b[$key] );
elseif ( $key == 'arg' ):
$c->addAttribute( 'arg', $b[$key] );
$c->addChild( 'arg', $b[$key]);
elseif ( $key == 'type' ):
$c->addAttribute( 'type', $b[$key] );
elseif ( $key == 'valid' ):
Expand All @@ -207,6 +207,31 @@ public function toxml( $a=null, $format='array' ) {
else:
$c->$key = $b[$key];
endif;
elseif ( $key == 'subtitle' ):
if ( gettype( $b[$key] ) == 'array' ):
$subtitle_types = ['shift', 'fn', 'ctrl', 'alt', 'cmd'];
$subtitles = $b[$key];
$subtitle_keys = array_keys( $subtitles );

foreach( $subtitle_keys as $subtitle_key ):
$subtitle_element = $c->addChild( 'subtitle', $subtitles[$subtitle_key] );
if ( in_array( $subtitle_key, $subtitle_types, true ) ):
$subtitle_element->addAttribute( 'mod', $subtitle_key );
endif;
endforeach;
else:
$c->$key = $b[$key];
endif;
elseif ( $key == 'text' && gettype($b[$key]) == 'array' ):
$text_types = ['copy', 'largetype'];
$texts = $b[$key];
$text_keys = array_keys( $texts );

foreach( $text_keys as $text_key ):
if ( in_array( $text_key, $text_types ) ):
$c->addChild( 'text', $texts[$text_key] )->addAttribute( 'type', $text_key );
endif;
endforeach;
else:
$c->$key = $b[$key];
endif;
Expand Down Expand Up @@ -249,10 +274,9 @@ public function set( $a=null, $b=null, $c=null )
{
if ( is_array( $a ) ):
if ( file_exists( $b ) ):
$temp = $this->path.'/'.$b;
if ( $b == $temp ):
$b = $this->path."/".$b;
endif;
if ( file_exists( $this->path.'/'.$b ) ):
$b = $this->path.'/'.$b;
endif;
elseif ( file_exists( $this->data."/".$b ) ):
$b = $this->data."/".$b;
elseif ( file_exists( $this->cache."/".$b ) ):
Expand All @@ -262,9 +286,8 @@ public function set( $a=null, $b=null, $c=null )
endif;
else:
if ( file_exists( $c ) ):
$temp = $this->path.'/'.$c;
if ( $c == $temp ):
$c = $this->path."/".$c;
if ( file_exists( $this->path.'/'.$c ) ):
$c = $this->path.'/'.$c;
endif;
elseif ( file_exists( $this->data."/".$c ) ):
$c = $this->data."/".$c;
Expand Down Expand Up @@ -295,25 +318,24 @@ public function set( $a=null, $b=null, $c=null )
public function get( $a, $b ) {

if ( file_exists( $b ) ):
$temp = $this->path.'/'.$b;
if ( $b == $temp ):
$b = $this->path."/".$b;
if ( file_exists( $this->path.'/'.$b ) ):
$b = $this->path.'/'.$b;
endif;
elseif ( file_exists( $this->data."/".$b ) ):
elseif ( file_exists( $this->data."/".$b ) ):
$b = $this->data."/".$b;
elseif ( file_exists( $this->cache."/".$b ) ):
$b = $this->cache."/".$b;
else:
return false;
endif;

exec( 'defaults read "'. $b .'" '.$a, $out ); // Execute system call to read plist value
$out = `defaults read "$b" $a`; // Execute system call to read plist value

if ( $out == "" ):
return false;
endif;

$out = $out[0];
$out = trim($out);
return $out; // Return item value
}

Expand Down Expand Up @@ -383,9 +405,8 @@ public function mdfind( $query )
public function write( $a, $b )
{
if ( file_exists( $b ) ):
$temp = $this->path.'/'.$b;
if ( $b == $temp ):
$b = $this->path."/".$b;
if ( file_exists( $this->path.'/'.$b ) ):
$b = $this->path.'/'.$b;
endif;
elseif ( file_exists( $this->data."/".$b ) ):
$b = $this->data."/".$b;
Expand Down Expand Up @@ -418,9 +439,8 @@ public function write( $a, $b )
public function read( $a )
{
if ( file_exists( $a ) ):
$temp = $path.'/'.$a;
if ( $a === $temp ):
$a = $this->path."/".$a;
if ( file_exists( $this->path.'/'.$a ) ):
$a = $this->path.'/'.$a;
endif;
elseif ( file_exists( $this->data."/".$a ) ):
$a = $this->data."/".$a;
Expand All @@ -446,13 +466,14 @@ public function read( $a )
* @param $uid - the uid of the result, should be unique
* @param $arg - the argument that will be passed on
* @param $title - The title of the result item
* @param $sub - The subtitle text for the result item
* @param $sub - The subtitle text for the result item; can be an array of mod values or a string
* @param $icon - the icon to use for the result item
* @param $valid - sets whether the result item can be actioned
* @param $text - array with keys 'copy' and/or 'largetype' and their respective string values
* @param $auto - the autocomplete value for the result item
* @return array - array item to be passed back to Alfred
*/
public function result( $uid, $arg, $title, $sub, $icon, $valid='yes', $auto=null, $type=null )
public function result( $uid, $arg, $title, $sub, $icon, $valid='yes', $text=null, $auto=null, $type=null )
{
$temp = array(
'uid' => $uid,
Expand All @@ -461,10 +482,11 @@ public function result( $uid, $arg, $title, $sub, $icon, $valid='yes', $auto=nul
'subtitle' => $sub,
'icon' => $icon,
'valid' => $valid,
'text' => $text,
'autocomplete' => $auto,
'type' => $type
);

if ( is_null( $type ) ):
unset( $temp['type'] );
endif;
Expand All @@ -473,5 +495,15 @@ public function result( $uid, $arg, $title, $sub, $icon, $valid='yes', $auto=nul

return $temp;
}

}

public function internet()
{
$internet = @fsockopen("www.google.com",80);
if($internet):
fclose($internet);
return true;
else:
return false;
endif;
}
}