Skip to main content
Commonmark migration
Source Link

##PowerShell v3+ 110 99 107 103 Bytes

PowerShell v3+ 110 99 107 103 Bytes

iwr($x=((iwr "xkcd.com/$args").images|?{$_.title})).src.Trim("/") -outf x.jpg;if($x){ii x.jpg;$x.title} 

Thanks to Timmy for helping save some bytes by using inline assignments.

If no arguments are passed then $args is null and it will just get the current comic. Download the picture, by matching the one with alt text, into a file in the current running directory of the script. Then display it with the default viewer of jpg's. The alt text is then displayed to console. iwr is an alias for Invoke-WebRequest

If the number passed (or any invalid input for that matter) does not match the process fails with at least a 404 error.

iwr( # Request the comic image from XKCD $x=((iwr "xkcd.com/$args").images| # Primary search to locate either the current image # or one matching an argument passed ?{$_.title})) # Find the image with alt text .src.Trim("/") # Using the images associated link and strip the leading slashes -outf x.jpg # Output the image to the directory local to where the script was run if($x){ # Test if the image acquisition was successful ii x.jpg # Open the picture in with the default jpg viewer $x.title # Display alt text to console } # I'm a closing bracket. 

##PowerShell v3+ 110 99 107 103 Bytes

iwr($x=((iwr "xkcd.com/$args").images|?{$_.title})).src.Trim("/") -outf x.jpg;if($x){ii x.jpg;$x.title} 

Thanks to Timmy for helping save some bytes by using inline assignments.

If no arguments are passed then $args is null and it will just get the current comic. Download the picture, by matching the one with alt text, into a file in the current running directory of the script. Then display it with the default viewer of jpg's. The alt text is then displayed to console. iwr is an alias for Invoke-WebRequest

If the number passed (or any invalid input for that matter) does not match the process fails with at least a 404 error.

iwr( # Request the comic image from XKCD $x=((iwr "xkcd.com/$args").images| # Primary search to locate either the current image # or one matching an argument passed ?{$_.title})) # Find the image with alt text .src.Trim("/") # Using the images associated link and strip the leading slashes -outf x.jpg # Output the image to the directory local to where the script was run if($x){ # Test if the image acquisition was successful ii x.jpg # Open the picture in with the default jpg viewer $x.title # Display alt text to console } # I'm a closing bracket. 

PowerShell v3+ 110 99 107 103 Bytes

iwr($x=((iwr "xkcd.com/$args").images|?{$_.title})).src.Trim("/") -outf x.jpg;if($x){ii x.jpg;$x.title} 

Thanks to Timmy for helping save some bytes by using inline assignments.

If no arguments are passed then $args is null and it will just get the current comic. Download the picture, by matching the one with alt text, into a file in the current running directory of the script. Then display it with the default viewer of jpg's. The alt text is then displayed to console. iwr is an alias for Invoke-WebRequest

If the number passed (or any invalid input for that matter) does not match the process fails with at least a 404 error.

iwr( # Request the comic image from XKCD $x=((iwr "xkcd.com/$args").images| # Primary search to locate either the current image # or one matching an argument passed ?{$_.title})) # Find the image with alt text .src.Trim("/") # Using the images associated link and strip the leading slashes -outf x.jpg # Output the image to the directory local to where the script was run if($x){ # Test if the image acquisition was successful ii x.jpg # Open the picture in with the default jpg viewer $x.title # Display alt text to console } # I'm a closing bracket. 
added 1 character in body
Source Link
Matt
  • 1.1k
  • 12
  • 14

##PowerShell v3+ 110 99 107 102103 Bytes

iwr($x=((iwr "xkcd.com/$args").images|?{$_.title})).src.Trim("/") -outf x.jpgifjpg;if($x){ii x.jpg;$x.title} 

Thanks to Timmy for helping save some bytes by using inline assignments.

If no arguments are passed then $args is null and it will just get the current comic. Download the picture, by matching the one with alt text, into a file in the current running directory of the script. Then display it with the default viewer of jpg's. The alt text is then displayed to console. iwr is an alias for Invoke-WebRequest

If the number passed (or any invalid input for that matter) does not match the process fails with at least a 404 error.

iwr( # Request the comic image from XKCD $x=((iwr "xkcd.com/$args").images| # Primary search to locate either the current image # or one matching an argument passed ?{$_.title})) # Find the image with alt text .src.Trim("/") # Using the images associated link and strip the leading slashes -outf x.jpg # Output the image to the directory local to where the script was run if($x){ # Test if the image acquisition was successful ii x.jpg # Open the picture in with the default jpg viewer $x.title # Display alt text to console } # I'm a closing bracket. 

##PowerShell v3+ 110 99 107 102 Bytes

iwr($x=((iwr "xkcd.com/$args").images|?{$_.title})).src.Trim("/") -outf x.jpgif($x){ii x.jpg;$x.title} 

Thanks to Timmy for helping save some bytes by using inline assignments.

If no arguments are passed then $args is null and it will just get the current comic. Download the picture, by matching the one with alt text, into a file in the current running directory of the script. Then display it with the default viewer of jpg's. The alt text is then displayed to console. iwr is an alias for Invoke-WebRequest

If the number passed (or any invalid input for that matter) does not match the process fails with at least a 404 error.

iwr( # Request the comic image from XKCD $x=((iwr "xkcd.com/$args").images| # Primary search to locate either the current image # or one matching an argument passed ?{$_.title})) # Find the image with alt text .src.Trim("/") # Using the images associated link and strip the leading slashes -outf x.jpg # Output the image to the directory local to where the script was run if($x){ # Test if the image acquisition was successful ii x.jpg # Open the picture in with the default jpg viewer $x.title # Display alt text to console } # I'm a closing bracket. 

##PowerShell v3+ 110 99 107 103 Bytes

iwr($x=((iwr "xkcd.com/$args").images|?{$_.title})).src.Trim("/") -outf x.jpg;if($x){ii x.jpg;$x.title} 

Thanks to Timmy for helping save some bytes by using inline assignments.

If no arguments are passed then $args is null and it will just get the current comic. Download the picture, by matching the one with alt text, into a file in the current running directory of the script. Then display it with the default viewer of jpg's. The alt text is then displayed to console. iwr is an alias for Invoke-WebRequest

If the number passed (or any invalid input for that matter) does not match the process fails with at least a 404 error.

iwr( # Request the comic image from XKCD $x=((iwr "xkcd.com/$args").images| # Primary search to locate either the current image # or one matching an argument passed ?{$_.title})) # Find the image with alt text .src.Trim("/") # Using the images associated link and strip the leading slashes -outf x.jpg # Output the image to the directory local to where the script was run if($x){ # Test if the image acquisition was successful ii x.jpg # Open the picture in with the default jpg viewer $x.title # Display alt text to console } # I'm a closing bracket. 
added 70 characters in body
Source Link
Matt
  • 1.1k
  • 12
  • 14

##PowerShell v3+ 110 99 107 102 Bytes

iwr($x=((iwr "xkcd.com/$args").images|?{$_.title})).src.Trim("/") -outf x.jpgif($x){ii x.jpg;$x.title} 

Thanks to Timmy for helping save some bytes by using inline assignments.

If no arguments are passed then $args is null and it will just get the current comic. Download the picture, by matching the one with alt text, into a file in the current running directory of the script. Then display it with the default viewer of jpg's. The alt text is then displayed to console. iwr is an alias for Invoke-WebRequest

If the number passed (or any invalid input for that matter) does not match the process fails with at least a 404 error.

iwr( # Request the comic image from XKCD $x=((iwr "xkcd.com/$args").images| # Primary search to locate either the current image # or one matching an argument passed ?{$_.title})) # Find the image with alt text .src.Trim("/") # Using the images accociatedassociated link and strip the leading slashes -outf x.jpg # Output the image to the directory local to where the script was run if($x){ # Test if the image acquisition was successful ii x.jpg # Open the picture in with the default jpg viewer $x.title # Display alt text to console } # I'm a closing bracket. 

##PowerShell v3+ 110 99 107 102 Bytes

iwr($x=((iwr "xkcd.com/$args").images|?{$_.title})).src.Trim("/") -outf x.jpgif($x){ii x.jpg;$x.title} 

Thanks to Timmy for helping save some bytes.

If no arguments are passed then $args is null and it will just get the current comic. Download the picture, by matching the one with alt text, into a file in the current running directory of the script. Then display it with the default viewer of jpg's. The alt text is then displayed to console.

If the number passed (or any invalid input for that matter) does not match the process fails with at least a 404 error.

iwr( # Request the comic image from XKCD $x=((iwr "xkcd.com/$args").images| # Primary search to locate either the current image # or one matching an argument passed ?{$_.title})) # Find the image with alt text .src.Trim("/") # Using the images accociated link and strip the leading slashes -outf x.jpg # Output the image to the directory local to where the script was run if($x){ # Test if the image acquisition was successful ii x.jpg # Open the picture in with the default jpg viewer $x.title # Display alt text to console } # I'm a closing bracket. 

##PowerShell v3+ 110 99 107 102 Bytes

iwr($x=((iwr "xkcd.com/$args").images|?{$_.title})).src.Trim("/") -outf x.jpgif($x){ii x.jpg;$x.title} 

Thanks to Timmy for helping save some bytes by using inline assignments.

If no arguments are passed then $args is null and it will just get the current comic. Download the picture, by matching the one with alt text, into a file in the current running directory of the script. Then display it with the default viewer of jpg's. The alt text is then displayed to console. iwr is an alias for Invoke-WebRequest

If the number passed (or any invalid input for that matter) does not match the process fails with at least a 404 error.

iwr( # Request the comic image from XKCD $x=((iwr "xkcd.com/$args").images| # Primary search to locate either the current image # or one matching an argument passed ?{$_.title})) # Find the image with alt text .src.Trim("/") # Using the images associated link and strip the leading slashes -outf x.jpg # Output the image to the directory local to where the script was run if($x){ # Test if the image acquisition was successful ii x.jpg # Open the picture in with the default jpg viewer $x.title # Display alt text to console } # I'm a closing bracket. 
added 48 characters in body
Source Link
Matt
  • 1.1k
  • 12
  • 14
Loading
deleted 141 characters in body
Source Link
Matt
  • 1.1k
  • 12
  • 14
Loading
added 159 characters in body
Source Link
Matt
  • 1.1k
  • 12
  • 14
Loading
added 71 characters in body
Source Link
Matt
  • 1.1k
  • 12
  • 14
Loading
added 197 characters in body
Source Link
Matt
  • 1.1k
  • 12
  • 14
Loading
Post Undeleted by Matt
added 221 characters in body
Source Link
Matt
  • 1.1k
  • 12
  • 14
Loading
Post Deleted by Matt
Source Link
Matt
  • 1.1k
  • 12
  • 14
Loading